0
votes

I am updating a groovy script which build a test runner suite inside SoapUI. The scripts scan a folders and add test case for each file in each folders.

The problem I am trying to solve is that the script is using eachFileMatch() which does not have a consistent behavior between Windows and Unix file systems. I need to update the script so that files are listed alphabetically.

I am quite new to groovy so I don't know where to get started. Saw that a sort() method does exist but I am not sure I can use it on eachFileMatch.

Here's the code snippet I need to adapt :

new File(projectPathTest+"/nord").eachDir{dir->
  log.info("Dir > "+dir);
  operation = dir.name
  def wsdlTestCase = testSuite.addNewTestCase( operation )
  wsdlTestCase.setFailOnError(false)
  dir.eachFileMatch(~/.*_request\.xml/){file->
    // Need Alphabetically sorting here
    log.info("File >> "+file)
    addTestStep(operation, file, wsdlTestCase, projectPath, endPoint)       
  }

Any starting point to do it will the groovy approach would be really appreciated as for now i don't have time to delve into the groovy API.

Regards }

1

1 Answers

0
votes

You can collect the files in a TreeSet which will maintain their sort order and then iterate over the set to display or otherwise act on your collection of files.

TreeSet<File> files = new TreeSet<File>()

dir.eachFileMatch(~/.*_request\.xml/){file->
    files << file
}

files.each { f->
    // log or do whatever with the files in order
}

If you need this ordering over all the files, you will need to put the TreeSet outside of the eachDir closure.