[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[news.eclipse.tools] JUnit behaving badly

I have 2 weird  issues and before I open a bug, hopefully someone here can
shed some light.

1.) I have wriiten an EJB and successfully deployed it.  I then proceeded to
create a JUnit TestCase in eclipse.  The creation of the testcase was fine,
but running it causes an error ( see stacktrace below).  The test needs to
take a password, run it through MD5 and then base 64 encode the result
(method included below).  If I execute the testcase from the command line
then all is well but from within eclipse I get the following:

.java.security.NoSuchAlgorithmException: Algorithm HmacMD5 not available
at javax.crypto.SunJCE_b.a(DashoA6275)
at javax.crypto.Mac.getInstance(DashoA6275)
at com.watutech.ejb.common.util.Utils.getMD5Hash(Utils.java:59)
at
com.watutech.firestorm.tests.UserBeanTest.testEjbCreate(UserBeanTest.java:51
)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39
)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl
.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at junit.textui.TestRunner.doRun(TestRunner.java:116)
at junit.textui.TestRunner.doRun(TestRunner.java:109)
at junit.textui.TestRunner.run(TestRunner.java:72)
at com.watutech.firestorm.tests.AllTests.main(AllTests.java:19)
Time: 2.193
OK (1 test)

I've checkd that I'm running in a 1.4 vm so the testcase does have access to
the required files, and running it on the command line verifies that it is
working.

public static String encode( String text )
{
    try
    {
        Mac mac = Mac.getInstance("HmacMD5");
        SecretKeySpec sk =
          new SecretKeySpec("my secret".getBytes(), "HmacMD5");
        mac.init(sk);
        byte[] result = mac.doFinal( text.getBytes());
        BASE64Encoder b64Encoder = new BASE64Encoder();
        return b64Encoder.encode( result );
    }
    catch (InvalidKeyException e)
    {
        e.printStackTrace();
    }
    catch (NoSuchAlgorithmException e)
    {
        e.printStackTrace();
    }
    catch (IllegalStateException e)
    {
        e.printStackTrace();
    }
    return null;
}

2.) I used eclipse to create a TestSuite, AllTests and selected to include a
main method and to use the junit.textui.TestRunner.  The main method
generated was:

public static void main(String[] args)
{
    junit.textui.TestRunner.run(AllTests.class);
}
but I had to change it to
public static void main(String[] args)
{
    junit.textui.TestRunner.run(AllTests.suite());
}
to get it to work.  Otherwise I got the following exception:

.F
Time: 0.01
There was 1 failure:
1) warning(junit.framework.TestSuite$1)junit.framework.AssertionFailedError:
No tests found in com.watutech.firestorm.tests.AllTests
at com.watutech.firestorm.tests.AllTests.main(AllTests.java:19)
FAILURES!!!
Tests run: 1, Failures: 1, Errors: 0

The documentation seems to indicate that the run(Class) method will extract
all test*() methods, put them in a suite and run that, but since there are
no test*() methods in AllTests I get the warning.  So is this a code
generation bug or did I miss something?

Binyan