This is my first real foray into the realm of junit tests...
And I got mixed results, so far.
I would really appreciate it if someone interested in converting tests to junit, or someone who knows how junit tests are supposed to look could review what I've done so far and give me feedback...
The attached patch -
DERBY-1496_tmp_072206.* - doesn't modify testSecMec.java at all...
Because testSecMec.java extends dataSourcePermissions_net.java which extends dataSourcePermissions.java and I'm currently stuck on converting the dataSourcePermissions_net test.
This is what I did:
I started converting jdbcapi/dataSourcePermissions.java which seemed to go well enough.
My first step was to just run the test as a junit test, which meant:
- remove main method
- add setUp method
- add constructor for taking test name
- extend from BaseJDBCTestCase
- replace cleanUp with tearDown
- add test methods that start with 'test' for the actual string
- replace chatty System.out.printlns with println
Then I ran this test with
java -Dverbose=true -Dkeepfiles=true -Djvmflags=-Dderby.test.debug=true org.apache.derbyTesting.functionTests.harness.RunTest jdbcapi/dataSourcePermissions.junit
The resulting .out was hard to deal with using my vdiff32 on windows, so I
went ahead and added DEBUG and .DEBUG to Sed.java to be filtered during my conversion
Now the resulting diff was easy to oversee.
The next step was to convert all the checkConnections to assertTrue.
Reran the test, then reran withouth the derby.test.debug and got rid of the .out.
As an afterthought, I created a testSuite method.
So far so good, much encouraged, I went on to work on dataSourcePermissions_net.java.
And that's as far as I got.
One of the aspects is that I had to add grant a number of permissions that are granted to various jars already, but apparently had to be added again - maybe to junit?
There seemed to be no efficient way to get a simple connection to networkserver using a different port than the default 1527. I was quite surprised really that the original test was able to do this with ij.startJBMS().
I contacted Kathey on the IRC and she said the 20000 was put in at a time that there was no startServer=false property, so it could go back to 1527 now.
So that's what the test is doing currently, but I would like to make a way to get connections to a different port.
The current test executes setUp and tearDown a number of times. Each time it also calls the super methods. I think I did this wrong, but I am not clear on how to do it instead.
Probably some of the setup needs to go into a decorator. I'll experiment with that next.
For some reason, I currently only get output for the testDriverManagerPermissions subtest.
It's very strange, in the (eclipse) debugger I can see that junit apparently does recognize that it needs to do something with these tests, but all it ends up doing are setUps and tearDowns and shutdowns and starts. No doubt because of me call supers, but I still don't see why it's not running the tests.
So, I'll keep muddling on, but I thought I'd log what I've done so far.
Obviously, this patch is not suitable for commit.