Hi,

I try to have a simpler example to test ClassLoader when I run my tests with
M2. (in this example, I don't use UISpec4J) With this example, I always have
a kind of class not found exception.

Here is a part of my POM file :

                                    <plugin>
                                       <groupId> org.apache.maven.plugins
</groupId>

<artifactId>maven-surefire-plugin</artifactId>
                                       <configuration>
                                           <forkMode>once</forkMode>
                                           <configuration>

<childDelegation>true</childDelegation>
                                           </configuration>
                                       </configuration>
                                   </plugin>



Here is the method of test class that I used  :

   public void testClassLoader() throws Exception {
       System.setProperty("awt.toolkit", MyToolkit.class.getName());
       Toolkit defaultToolkit = Toolkit.getDefaultToolkit();

       assertNotNull(defaultToolkit);
       System.out.println ("defaultToolkit.getClass()= " +
defaultToolkit.getClass());
   }



The result by using IDEA IntelliJ :
################################################################
defaultToolkit.getClass() = class com.agf.MyToolkit
################################################################



But the result by using maven2 is different. I get this exception :
################################################################
testClassLoader(com.agf.MyTest)  Time elapsed: 0.062 sec  <<< ERROR!

java.awt.AWTError: Toolkit not found: com.agf.MyToolkit
           at java.awt.Toolkit$2.run(Toolkit.java:828)
           at java.security.AccessController.doPrivileged(Native Method)
           at java.awt.Toolkit.getDefaultToolkit(Toolkit.java:804)
           at com.agf.MyTest.testClassLoader(MyTest.java:14)
################################################################


I think that surfire manage different ClassLoaders and the Toolkit is not in
the good ClassLoader. Can anyone confim that ? and explain me how to solve
this problem ?

Thanks,
Olivier



2006/8/16, Olivier Catteau < [EMAIL PROTECTED]>:

Hi,

I've got a problem when I try to use UISpec4J for unit testing Swing based
applications.
Iv'e got a test class that extends UISpecTestCase. In IntelliJ, my test
works witout any problem. But, when I try to run my test by using Maven2, it
throws an exception.



###################################################################################################################
[INFO] [surefire:test]
[INFO] Surefire report directory:
C:\DEV\projects\migration\agf-agent-bootstrap\target\surefire-reports
org.apache.maven.surefire.booter.SurefireExecutionException:
com.agf.workflow.gui.wizard.WizardWindowTest; nested exception is jav
a.awt.AWTError: Toolkit not found:
org.uispec4j.interception.toolkit.UISpecToolkit ; nested exception is
org.apache.maven.surefire.
testset.TestSetFailedException:
com.agf.workflow.gui.wizard.WizardWindowTest; nested exception is
java.awt.AWTError: Toolkit not f
ound: org.uispec4j.interception.toolkit.UISpecToolkit
org.apache.maven.surefire.testset.TestSetFailedException:
com.agf.workflow.gui.wizard.WizardWindowTest; nested exception is
java.awt.AWTError: Toolkit not found:
org.uispec4j.interception.toolkit.UISpecToolkit
java.awt.AWTError : Toolkit not found:
org.uispec4j.interception.toolkit.UISpecToolkit
        at java.awt.Toolkit$2.run(Toolkit.java:828)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.awt.Toolkit.getDefaultToolkit (Toolkit.java:804)
        at javax.swing.UIManager.<clinit>(UIManager.java:313)
        at org.uispec4j.interception.ui.UISpecLF.init(UISpecLF.java:11)
        at org.uispec4j.UISpec4J.init(UISpec4J.java:21)
        at org.uispec4j.UISpecTestCase.<clinit>(UISpecTestCase.java:31)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native
Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance (
NativeConstructorAccessorImpl.java:39)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(
DelegatingConstructorAccessorImpl.java:27)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:494)
        at junit.framework.TestSuite.createTest(TestSuite.java:131)
        at junit.framework.TestSuite.addTestMethod(TestSuite.java:114)
        at junit.framework.TestSuite.<init>(TestSuite.java:75)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native
Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(
NativeConstructorAccessorImpl.java:39)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance (
DelegatingConstructorAccessorImpl.java:27)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:494)
        at
org.apache.maven.surefire.junit.JUnitTestSet.constructTestObject(
JUnitTestSet.java:148)
        at org.apache.maven.surefire.junit.JUnitTestSet.getTestCount(
JUnitTestSet.java:244)
        at
org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.locateTestSets(
AbstractDirectoryTestSuite.java:101)
        at org.apache.maven.surefire.Surefire.createSuiteFromDefinition(
Surefire.java:147)
        at org.apache.maven.surefire.Surefire.run(Surefire.java:108)
        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:585)
        at
org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(
SurefireBooter.java:225)
        at org.apache.maven.surefire.booter.SurefireBooter.main (
SurefireBooter.java:747)

###################################################################################################################


It seems to be a problem of classloader that comes from UISpec4J. I don't
know how it is managed by surefire. Perhaps it comes from this piece of code
:

##############################################################
  private static void setAwtToolkitProperty() {
    try {
      Class.forName(WINDOWS_SYSTEM_DEFAULT_VALUE);
      awtToolkit = WINDOWS_SYSTEM_DEFAULT_VALUE;
    }
    catch (ClassNotFoundException e) {
      try {
        Class.forName(UNIX_SYSTEM_DEFAULT_VALUE);
        awtToolkit = UNIX_SYSTEM_DEFAULT_VALUE;
      }
      catch (ClassNotFoundException e1) {
        throw new AWTError("Unable to locate AWT Toolkit");
      }
    }
  }
##############################################################


Has anyone have any idea about the source of my problem ? and how to
resolve this problem ? Or can anyone explain how surfire manage classloader
?

Thanks.
Olivier

Reply via email to