This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
Am using jdk1.6 and want to find an easy way, from within a JUnittest, to locate files in my project of a specific type
I want my test to find all files that end with "hbm.xml" and once i have a list of the files, to then
read their contents.
I can do the below individually for one file but I've to specify it's path:
I don't want to have to update my test if a user adds a new hbm.xml file. I'm sure theres some way of doing this in java.
Any help would be great.
Cheers. Ro.
Check out File.listFiles(FileFilter) or File.listFiles(FilenameFilter). The former is probably better because that one allows you to list folders as well, so you can check the folder recursively. In code, with a few gaps:
Taking a step back: why are you trying to do this?
Ronan Dowd
Ranch Hand
Joined: Jan 21, 2006
Posts: 84
posted
0
Hi, am using hibernate in my application and want to, as part of a JUnit test, execute all named queries that i've defined. In hibernate, named queries are defined in files
ending in "hbm.xml" so I want to find all files in my application with this file ending then I'm going to use the java Matcher and Pattern classes to
find, in each "hbm.xml" file the name of the query. The i'm going to execute each query. I tried to see if there was a way in hibernate to get all named queries which you've
defined but there doesn't appear to be. Hence me going the java route of finding the file and parsing the contents..
Ro.
I'm not sure if that makes any sense to me: it doesn't test that the named queries you actually *need* are there, that would have to be done on a query-by-query basis, by code that knows (a) what the query is named, and (b) what the query is supposed to return.
I'm just not really sure what you're testing doing what you want to do is all.
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.
subject: Searching for files of a specific type in jdk1.4