public void testBadFetchLocationWin() throws Exception {
    if (Config.DEFAULT.isConfigured() && SystemUtils.IS_OS_WINDOWS) {
      RTCLoginInfo loginInfo = Config.DEFAULT.getLoginInfo();

      String testName = getTestName() + System.currentTimeMillis();
      String fetchLocation = "invalid/questionmark?/character/is/not/ok";

      @SuppressWarnings("unchecked")
      Map<String, String> setupArtifacts =
          (Map<String, String>)
              testingFacade.invoke(
                  "testBadFetchLocation",
                  new Class[] {
                    String.class, // serverURL,
                    String.class, // userId,
                    String.class, // password,
                    int.class, // timeout,
                    String.class, // workspaceName,
                    String.class, // componentName,
                    String.class, // hjPath,
                    String.class
                  }, // buildPath
                  loginInfo.getServerUri(),
                  loginInfo.getUserId(),
                  loginInfo.getPassword(),
                  loginInfo.getTimeout(),
                  testName,
                  getTestName(),
                  sandboxDir.getPath(),
                  fetchLocation);

      // clean up
      testingFacade.invoke(
          "tearDown",
          new Class[] {
            String.class, // serverURL,
            String.class, // userId,
            String.class, // password,
            int.class, // timeout,
            Map.class
          }, // setupArtifacts
          loginInfo.getServerUri(),
          loginInfo.getUserId(),
          loginInfo.getPassword(),
          loginInfo.getTimeout(),
          setupArtifacts);
    }
  }
  public void testGoodAbsoluteFetchLocationWin() throws Exception {
    if (Config.DEFAULT.isConfigured()) {
      RTCLoginInfo loginInfo = Config.DEFAULT.getLoginInfo();

      String testName = getTestName() + System.currentTimeMillis();
      String fetchLocation = "C:\\absolute\\is\\ok\\too";

      @SuppressWarnings("unchecked")
      Map<String, String> setupArtifacts =
          (Map<String, String>)
              testingFacade.invoke(
                  "testGoodFetchLocation",
                  new Class[] {
                    String.class, // serverURL,
                    String.class, // userId,
                    String.class, // password,
                    int.class, // timeout,
                    String.class, // workspaceName,
                    String.class, // componentName,
                    String.class, // hjPath,
                    String.class
                  }, // buildPath
                  loginInfo.getServerUri(),
                  loginInfo.getUserId(),
                  loginInfo.getPassword(),
                  loginInfo.getTimeout(),
                  testName,
                  getTestName(),
                  sandboxDir.getPath(),
                  fetchLocation);

      // clean up
      testingFacade.invoke(
          "tearDown",
          new Class[] {
            String.class, // serverURL,
            String.class, // userId,
            String.class, // password,
            int.class, // timeout,
            Map.class
          }, // setupArtifacts
          loginInfo.getServerUri(),
          loginInfo.getUserId(),
          loginInfo.getPassword(),
          loginInfo.getTimeout(),
          setupArtifacts);
    }
  }
  public void testNewLoadRules() throws Exception {
    // create a build definition with new format load rules
    // load directory "."
    // delete directory before loading (dir has other stuff that will be deleted)
    // accept changes before loading

    // create a build engine
    // create a build request

    // verify that the buildConfiguration returns the load rules
    // and other settings.

    // checkout based on the request
    // make sure only the contents identified by the load rule was loaded
    // verify extra stuff deleted from sandbox directory
    // verify changes accepted
    if (Config.DEFAULT.isConfigured()) {
      RTCLoginInfo loginInfo = Config.DEFAULT.getLoginInfo();

      String testName = getTestName() + System.currentTimeMillis();
      String fetchLocation = ".";

      @SuppressWarnings("unchecked")
      Map<String, String> setupArtifacts =
          (Map<String, String>)
              testingFacade.invoke(
                  "testNewLoadRules",
                  new Class[] {
                    String.class, // serverURL,
                    String.class, // userId,
                    String.class, // password,
                    int.class, // timeout,
                    String.class, // workspaceName,
                    String.class, // componentName,
                    String.class, // hjPath,
                    String.class
                  }, // buildPath
                  loginInfo.getServerUri(),
                  loginInfo.getUserId(),
                  loginInfo.getPassword(),
                  loginInfo.getTimeout(),
                  testName,
                  getTestName(),
                  sandboxDir.getPath(),
                  fetchLocation);

      try {
        TaskListener listener = new StreamTaskListener(System.out, null);

        File changeLogFile = new File(sandboxDir, "RTCChangeLogFile");
        FileOutputStream changeLog = new FileOutputStream(changeLogFile);

        // put extraneous stuff in the load directory (which is different from sandbox cause
        // we want to get a the change log.
        File loadDir = new File(sandboxDir, "loadDir");
        assertTrue(loadDir.mkdirs());
        assertTrue(new File(loadDir, "abc").mkdirs());
        assertTrue(new File(loadDir, "def").mkdirs());
        assertTrue(new File(loadDir, "hij").mkdirs());

        // checkout the changes
        @SuppressWarnings("unchecked")
        Map<String, String> buildProperties =
            (Map<String, String>)
                testingFacade.invoke(
                    "checkout",
                    new Class[] {
                      String.class, // serverURL,
                      String.class, // userId,
                      String.class, // password,
                      int.class, // timeout,
                      String.class, // buildResultUUID,
                      String.class, // workspaceName,
                      String.class, // hjWorkspacePath,
                      OutputStream.class, // changeLog,
                      String.class, // baselineSetName,
                      Object.class, // listener
                      Locale.class
                    }, // clientLocale
                    loginInfo.getServerUri(),
                    loginInfo.getUserId(),
                    loginInfo.getPassword(),
                    loginInfo.getTimeout(),
                    setupArtifacts.get("buildResultItemId"),
                    null,
                    loadDir.getCanonicalPath(),
                    changeLog,
                    "Snapshot",
                    listener,
                    Locale.getDefault());

        String[] children = loadDir.list();
        Assert.assertEquals(
            3, children.length); // just what the load rule says to load (children of f) + metadata
        Assert.assertTrue(new File(loadDir, "a.txt").exists());
        Assert.assertTrue(new File(loadDir, "h.txt").exists());

        RTCChangeLogParser parser = new RTCChangeLogParser();
        FileReader changeLogReader = new FileReader(changeLogFile);
        RTCChangeLogSet result = (RTCChangeLogSet) parser.parse(null, null, changeLogReader);

        // verify the result
        int changeCount =
            result.getComponentChangeCount()
                + result.getChangeSetsAcceptedCount()
                + result.getChangeSetsDiscardedCount();
        Assert.assertEquals(1, changeCount);

        validateBuildProperties(
            setupArtifacts.get(ARTIFACT_WORKSPACE_ITEM_ID),
            fetchLocation,
            true,
            true,
            setupArtifacts.get("LoadRuleProperty"),
            false,
            "",
            result.getBaselineSetItemId(),
            changeCount,
            false,
            buildProperties);

      } finally {
        // clean up
        testingFacade.invoke(
            "tearDown",
            new Class[] {
              String.class, // serverURL,
              String.class, // userId,
              String.class, // password,
              int.class, // timeout,
              Map.class
            }, // setupArtifacts
            loginInfo.getServerUri(),
            loginInfo.getUserId(),
            loginInfo.getPassword(),
            loginInfo.getTimeout(),
            setupArtifacts);
      }
    }
  }
  public void testComponentLoading() throws Exception {
    // Test relative location for fetch destination
    // Test create folders for components
    // Test include/exclude components from the load

    // setup build request & verify BuildConfiguration
    // checkout & verify contents on disk
    if (Config.DEFAULT.isConfigured()) {

      String testName = getTestName() + System.currentTimeMillis();
      String fetchLocation = "path\\relative";
      RTCLoginInfo loginInfo = Config.DEFAULT.getLoginInfo();

      @SuppressWarnings("unchecked")
      Map<String, String> setupArtifacts =
          (Map<String, String>)
              testingFacade.invoke(
                  "testComponentLoading",
                  new Class[] {
                    String.class, // serverURL,
                    String.class, // userId,
                    String.class, // password,
                    int.class, // timeout,
                    String.class, // workspaceName,
                    String.class, // componentName,
                    String.class, // hjPath,
                    String.class
                  }, // buildPath
                  loginInfo.getServerUri(),
                  loginInfo.getUserId(),
                  loginInfo.getPassword(),
                  loginInfo.getTimeout(),
                  testName,
                  getTestName(),
                  sandboxDir.getPath(),
                  fetchLocation);

      try {
        TaskListener listener = new StreamTaskListener(System.out, null);

        File changeLogFile = new File(sandboxDir, "RTCChangeLogFile");
        FileOutputStream changeLog = new FileOutputStream(changeLogFile);

        // checkout the changes
        @SuppressWarnings("unchecked")
        Map<String, String> buildProperties =
            (Map<String, String>)
                testingFacade.invoke(
                    "checkout",
                    new Class[] {
                      String.class, // serverURL,
                      String.class, // userId,
                      String.class, // password,
                      int.class, // timeout,
                      String.class, // buildResultUUID,
                      String.class, // workspaceName,
                      String.class, // hjWorkspacePath,
                      OutputStream.class, // changeLog,
                      String.class, // baselineSetName,
                      Object.class, // listener
                      Locale.class
                    }, // clientLocale
                    loginInfo.getServerUri(),
                    loginInfo.getUserId(),
                    loginInfo.getPassword(),
                    loginInfo.getTimeout(),
                    setupArtifacts.get("buildResultItemId"),
                    null,
                    sandboxDir.getCanonicalPath(),
                    changeLog,
                    "Snapshot",
                    listener,
                    Locale.getDefault());

        String[] children = sandboxDir.list();
        Assert.assertEquals(2, children.length); // changelog plus what we loaded
        File actualRoot = new File(sandboxDir, "path\\relative");
        Assert.assertTrue(actualRoot.exists());
        children = actualRoot.list();
        assertEquals(2, children.length); // metadata plus component root folder
        File shareRoot = new File(actualRoot, getTestName());
        Assert.assertTrue(shareRoot.exists());
        Assert.assertTrue(new File(shareRoot, "f").exists());
        Assert.assertTrue(new File(shareRoot, "f/a.txt").exists());

        RTCChangeLogParser parser = new RTCChangeLogParser();
        FileReader changeLogReader = new FileReader(changeLogFile);
        RTCChangeLogSet result = (RTCChangeLogSet) parser.parse(null, null, changeLogReader);

        // verify the result
        int changeCount =
            result.getComponentChangeCount()
                + result.getChangeSetsAcceptedCount()
                + result.getChangeSetsDiscardedCount();
        Assert.assertFalse(result.isPersonalBuild());

        validateBuildProperties(
            setupArtifacts.get(ARTIFACT_WORKSPACE_ITEM_ID),
            fetchLocation,
            false,
            true,
            "",
            true,
            setupArtifacts.get(ARTIFACT_COMPONENT1_ITEM_ID),
            result.getBaselineSetItemId(),
            changeCount,
            true,
            buildProperties);

      } finally {
        // clean up
        testingFacade.invoke(
            "tearDown",
            new Class[] {
              String.class, // serverURL,
              String.class, // userId,
              String.class, // password,
              int.class, // timeout,
              Map.class
            }, // setupArtifacts
            loginInfo.getServerUri(),
            loginInfo.getUserId(),
            loginInfo.getPassword(),
            loginInfo.getTimeout(),
            setupArtifacts);
      }
    }
  }
  public void testPersonalBuild() throws Exception {
    // create a build definition
    // load directory ${propertyA}/here
    // build properties
    // myPropsFile =
    // ${team.scm.fetchDestination}/com.ibm.team.build.releng/continuous-buildsystem.properties
    // propertyA = loadDir
    // propertyB = a place (${propertyA}) to load some stuff
    // propertyC = original
    // using a load rule

    // create a build engine
    // create a build request for this test with personal build specified
    // (build workspace overridden, build engine is a random one, override load rule, override a
    // build property)

    // verify that the buildConfiguration returns the personal build workspace
    // as the workspace to be loaded
    // verify the load rule is changed
    // verify the build property is changed

    // checkout based on the request
    // make sure the personal build workspace was loaded and the load rule used
    if (Config.DEFAULT.isConfigured()) {
      RTCLoginInfo loginInfo = Config.DEFAULT.getLoginInfo();

      String testName = getTestName() + System.currentTimeMillis();

      @SuppressWarnings("unchecked")
      Map<String, String> setupArtifacts =
          (Map<String, String>)
              testingFacade.invoke(
                  "testPersonalBuild",
                  new Class[] {
                    String.class, // serverURL,
                    String.class, // userId,
                    String.class, // password,
                    int.class, // timeout,
                    String.class, // workspaceName,
                    String.class, // componentName,
                    String.class, // hjPath,
                    String.class
                  }, // buildPath
                  loginInfo.getServerUri(),
                  loginInfo.getUserId(),
                  loginInfo.getPassword(),
                  loginInfo.getTimeout(),
                  testName,
                  getTestName(),
                  sandboxDir.getPath(),
                  "${propertyA}/here");

      try {
        TaskListener listener = new StreamTaskListener(System.out, null);

        File changeLogFile = new File(sandboxDir, "RTCChangeLogFile");
        FileOutputStream changeLog = new FileOutputStream(changeLogFile);

        // put extraneous stuff in the load directory (which is different from sandbox cause
        // we want to get a the change log.
        File loadDir = new File(sandboxDir, "loadDir/here");
        assertTrue(loadDir.mkdirs());
        assertTrue(new File(loadDir, "abc").mkdirs());
        assertTrue(new File(loadDir, "def").mkdirs());
        assertTrue(new File(loadDir, "hij").mkdirs());

        // checkout the changes
        @SuppressWarnings("unchecked")
        Map<String, String> buildProperties =
            (Map<String, String>)
                testingFacade.invoke(
                    "checkout",
                    new Class[] {
                      String.class, // serverURL,
                      String.class, // userId,
                      String.class, // password,
                      int.class, // timeout,
                      String.class, // buildResultUUID,
                      String.class, // workspaceName,
                      String.class, // hjWorkspacePath,
                      OutputStream.class, // changeLog,
                      String.class, // baselineSetName,
                      Object.class, // listener
                      Locale.class
                    }, // clientLocale
                    loginInfo.getServerUri(),
                    loginInfo.getUserId(),
                    loginInfo.getPassword(),
                    loginInfo.getTimeout(),
                    setupArtifacts.get("buildResultItemId"),
                    null,
                    sandboxDir.getCanonicalPath(),
                    changeLog,
                    "Snapshot",
                    listener,
                    Locale.getDefault());

        String[] children = loadDir.list();
        Assert.assertEquals(
            5, children.length); // just what the load rule says to load (children of f) + metadata
        Assert.assertTrue(new File(loadDir, "b.txt").exists());
        Assert.assertFalse(new File(loadDir, "i.txt").exists());
        assertTrue(new File(loadDir, "abc").exists());
        assertTrue(new File(loadDir, "def").exists());
        assertTrue(new File(loadDir, "hij").exists());

        RTCChangeLogParser parser = new RTCChangeLogParser();
        FileReader changeLogReader = new FileReader(changeLogFile);
        RTCChangeLogSet result = (RTCChangeLogSet) parser.parse(null, null, changeLogReader);

        // verify the result
        Assert.assertTrue(result.isPersonalBuild());
        int changeCount =
            result.getComponentChangeCount()
                + result.getChangeSetsAcceptedCount()
                + result.getChangeSetsDiscardedCount();
        Assert.assertEquals(0, changeCount);

        validateBuildProperties(
            setupArtifacts.get(ARTIFACT_STREAM_ITEM_ID),
            "loadDir/here",
            false,
            true,
            setupArtifacts.get("LoadRuleProperty"),
            false,
            "",
            result.getBaselineSetItemId(),
            changeCount,
            false,
            buildProperties);

        // propertyA = loadDir
        // propertyB = a place (${propertyA}) to load some stuff
        // propertyC = original
        Assert.assertEquals("loadDir", buildProperties.get("propertyA"));
        Assert.assertEquals(
            "a place (loadDir) to load some stuff", buildProperties.get("propertyB"));
        Assert.assertEquals("overwritten", buildProperties.get("propertyC"));
      } finally {
        // clean up
        testingFacade.invoke(
            "tearDown",
            new Class[] {
              String.class, // serverURL,
              String.class, // userId,
              String.class, // password,
              int.class, // timeout,
              Map.class
            }, // setupArtifacts
            loginInfo.getServerUri(),
            loginInfo.getUserId(),
            loginInfo.getPassword(),
            loginInfo.getTimeout(),
            setupArtifacts);
      }
    }
  }