public List<IMethodInstance> intercept(List<IMethodInstance> methods, ITestContext context) {

    LogUtils.log("From SGTestNGMethodInterceptor");
    LogUtils.log("Number of tests to be run: " + methods.size());

    List<IMethodInstance> result = new ArrayList<IMethodInstance>();

    // this contains the method that should run before any other test
    List<IMethodInstance> startTests = new ArrayList<IMethodInstance>();

    // these are the cli and script tests and they should run last
    List<IMethodInstance> cliTests = new ArrayList<IMethodInstance>();
    List<IMethodInstance> scriptTests = new ArrayList<IMethodInstance>();

    List<IMethodInstance> otherTests = new ArrayList<IMethodInstance>();

    for (IMethodInstance m : methods) {
      String name = m.getMethod().getMethod().getDeclaringClass().getCanonicalName();

      if (name.contains("test.cli")) {
        cliTests.add(m);
      } else if (name.contains("test.scripts")) {
        scriptTests.add(m);
      } else if (name.contains("StartTest")) {
        startTests.add(m);
      } else {
        otherTests.add(m);
      }
    }

    result.addAll(startTests);
    result.addAll(otherTests);
    result.addAll(cliTests);
    result.addAll(scriptTests);

    return result;
  }
  @Test(timeOut = DEFAULT_TEST_TIMEOUT, enabled = true)
  public void tamperWithSecurityFileTest() throws Exception {

    String fakeCloudAdminUserAndPassword = "******";

    String originalFilePath = SecurityConstants.BUILD_SECURITY_FILE_PATH;
    String backupFilePath = originalFilePath + ".tempBackup";
    String fakeFilePath =
        CommandTestUtils.getPath("src/main/config/security/custom-spring-security.xml");
    File originalFile = new File(originalFilePath);
    File backupFile = new File(backupFilePath);
    File fakeFile = new File(fakeFilePath);
    String output = "no output";

    LogUtils.log("moving " + originalFilePath + " to " + backupFilePath);
    FileUtils.moveFile(originalFile, backupFile);

    try {
      LogUtils.log("copying " + fakeFilePath + " to " + originalFilePath);
      FileUtils.copyFile(fakeFile, originalFile);

      output =
          installApplicationAndWait(
              SIMPLE_APP_PATH,
              SIMPLE_APP_NAME,
              TIMEOUT_IN_MINUTES,
              fakeCloudAdminUserAndPassword,
              fakeCloudAdminUserAndPassword,
              true,
              null);

    } finally {
      LogUtils.log("deleting " + originalFilePath);
      try {
        FileUtils.deleteQuietly(originalFile);
      } catch (Exception e) {
        LogUtils.log("deletion of " + originalFilePath + " failed", e);
      }

      LogUtils.log("moving " + backupFilePath + " to " + originalFilePath);
      try {
        FileUtils.moveFile(backupFile, originalFile);
      } catch (Exception e) {
        LogUtils.log("moving of " + backupFilePath + " failed", e);
      }
    }

    assertTrue(
        "install access granted to viewer " + fakeCloudAdminUserAndPassword,
        output.contains(ACCESS_DENIED_MESSAGE));
  }
  private void setStatistics(
      final InternalProcessingUnit pu, final int expectedNumberOfInstances, long value)
      throws IOException, InterruptedException {

    ProcessingUnitInstance[] instances =
        repetitiveAssertNumberOfInstances(pu, expectedNumberOfInstances);

    for (ProcessingUnitInstance instance : instances) {
      String command =
          "connect localhost;invoke -instanceid "
              + instance.getInstanceId()
              + " --verbose "
              + SERVICE_NAME
              + " set "
              + value;
      String output = CommandTestUtils.runCommandAndWait(command);
      LogUtils.log(output);
    }
  }