SeamTestをEclipse上のTestNGプラグインから実行する方法
Seamのリファレンスマニュアルにしたがってexampleフォルダー内のreadme.txtにしたがって設定したのですが、もっとも簡単なregistrationサンプルアプリケーションの場合でも以下の例外となり、Eclipse内から正しく実行できませんでした。
Caused by: java.lang.RuntimeException: PROVIDER_URL not provided in jndi.properties. Automatic discovery not implemented yet. at org.jboss.naming.JBossRemotingContextFactory.getInitialContext(JBossRemotingContextFactory.java:158) at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:667) at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288) at javax.naming.InitialContext.init(InitialContext.java:223) at javax.naming.InitialContext.(InitialContext.java:197) at org.jboss.seam.util.Naming.getInitialContext(Naming.java:37) at org.jboss.seam.util.Naming.initInitialContext(Naming.java:59) at org.jboss.seam.util.Naming.getInitialContext(Naming.java:50) at org.jboss.seam.Component.instantiateSessionBean(Component.java:1400) at org.jboss.seam.Component.instantiate(Component.java:1364) at org.jboss.seam.Component.newInstance(Component.java:2122)
どうしてかなと思って、google検索してみたら、以下の情報がありました。
http://seamframework.org/Community/SeamTestNGJTAEntityManagerCannotAccessATransactions
そこで、TestNGのランチャーのクラスパスにlib\jboss-embedded-api.jarを追加してみました。そうしたら、今度は以下のような別の例外になりました。
ERROR [org.jboss.kernel.plugins.dependency.AbstractKernelController] Error installing to Described: name=BeanDeployer state=PreInstall java.lang.RuntimeException: java.lang.reflect.UndeclaredThrowableException at org.jboss.aop.util.ClassInfoMethodHashing.methodHash(ClassInfoMethodHashing.java:70) at org.jboss.aop.util.ClassInfoMethodHashing.addDeclaredMethods(ClassInfoMethodHashing.java:169) at org.jboss.aop.util.ClassInfoMethodHashing.populateMethodTables(ClassInfoMethodHashing.java:182) at org.jboss.aop.util.ClassInfoMethodHashing.populateMethodTables(ClassInfoMethodHashing.java:181) at org.jboss.aop.util.ClassInfoMethodHashing.populateMethodTables(ClassInfoMethodHashing.java:181) at org.jboss.aop.util.ClassInfoMethodHashing.populateMethodTables(ClassInfoMethodHashing.java:181) at org.jboss.aop.util.ClassInfoMethodHashing.populateMethodTables(ClassInfoMethodHashing.java:181) at org.jboss.aop.util.ClassInfoMethodHashing.populateMethodTables(ClassInfoMethodHashing.java:181) at org.jboss.aop.util.ClassInfoMethodHashing.getMethodMap(ClassInfoMethodHashing.java:188) at org.jboss.aop.microcontainer.integration.AOPDependencyBuilder.getMethodAnnotationDependencies(AOPDependencyBuilder.java:197) at org.jboss.aop.microcontainer.integration.AOPDependencyBuilder.getAnnotationDependencies(AOPDependencyBuilder.java:152) at org.jboss.aop.microcontainer.integration.AOPDependencyBuilder.getDependencies(AOPDependencyBuilder.java:130) at org.jboss.classadapter.plugins.BasicClassAdapter.getDependencies(BasicClassAdapter.java:80) at org.jboss.beans.info.plugins.AbstractBeanInfo.getDependencies(AbstractBeanInfo.java:211) at org.jboss.kernel.plugins.dependency.DescribeAction.installActionInternal(DescribeAction.java:53) at org.jboss.kernel.plugins.dependency.KernelControllerContextAction.installAction(KernelControllerContextAction.java:135) at org.jboss.kernel.plugins.dependency.KernelControllerContextAction.installAction(KernelControllerContextAction.java:46) at org.jboss.dependency.plugins.action.SimpleControllerContextAction.simpleInstallAction(SimpleControllerContextAction.java:62) at org.jboss.dependency.plugins.action.AccessControllerContextAction.install(AccessControllerContextAction.java:71) at org.jboss.dependency.plugins.AbstractControllerContextActions.install(AbstractControllerContextActions.java:51) at org.jboss.dependency.plugins.AbstractControllerContext.install(AbstractControllerContext.java:327) at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:1309) at org.jboss.dependency.plugins.AbstractController.incrementState(AbstractController.java:734) at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:862) at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:784) at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:574) at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:398) at org.jboss.kernel.plugins.deployment.AbstractKernelDeployer.deployBean(AbstractKernelDeployer.java:309) at org.jboss.kernel.plugins.deployment.AbstractKernelDeployer.deployBeans(AbstractKernelDeployer.java:279) at org.jboss.kernel.plugins.deployment.AbstractKernelDeployer.deploy(AbstractKernelDeployer.java:130) at org.jboss.kernel.plugins.deployment.xml.BeanXMLDeployer.deploy(BeanXMLDeployer.java:96) at org.jboss.embedded.Bootstrap.deployBaseBootstrapUrl(Bootstrap.java:130) at org.jboss.embedded.Bootstrap.bootstrapURL(Bootstrap.java:142) at org.jboss.embedded.Bootstrap.bootstrap(Bootstrap.java:183) at org.jboss.embedded.Bootstrap.bootstrap(Bootstrap.java:195) at org.jboss.seam.mock.EmbeddedBootstrap.startAndDeployResources(EmbeddedBootstrap.java:11) at org.jboss.seam.mock.AbstractSeamTest.startJbossEmbeddedIfNecessary(AbstractSeamTest.java:1024) at org.jboss.seam.mock.AbstractSeamTest.startSeam(AbstractSeamTest.java:915) at org.jboss.seam.mock.SeamTest.startSeam(SeamTest.java:58) 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:597) at org.testng.internal.MethodHelper.invokeMethod(MethodHelper.java:641) at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:525) at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:196) at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:126) at org.testng.SuiteRunner.privateRun(SuiteRunner.java:258) at org.testng.SuiteRunner.run(SuiteRunner.java:221) at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:40) at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:83) at org.testng.internal.thread.ThreadUtil$CountDownLatchedRunnable.run(ThreadUtil.java:151) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) at java.lang.Thread.run(Thread.java:619) Caused by: java.lang.reflect.UndeclaredThrowableException at org.jboss.reflect.plugins.ArrayInfoImpl.getType(ArrayInfoImpl.java:103) at org.jboss.reflect.plugins.ClassInfoImpl.isArray(ClassInfoImpl.java:495) at org.jboss.aop.util.ClassInfoMethodHashing.getTypeString(ClassInfoMethodHashing.java:149) at org.jboss.aop.util.ClassInfoMethodHashing.methodHash(ClassInfoMethodHashing.java:53) ... 54 more Caused by: java.lang.ClassNotFoundException: [Ljava.lang.Class; at java.net.URLClassLoader$1.run(URLClassLoader.java:202) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:190) at java.lang.ClassLoader.loadClass(ClassLoader.java:307) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) at java.lang.ClassLoader.loadClass(ClassLoader.java:248) at org.jboss.reflect.plugins.introspection.IntrospectionTypeInfoFactoryImpl.resolveComplexTypeInfo(IntrospectionTypeInfoFactoryImpl.java:367) at org.jboss.reflect.plugins.introspection.IntrospectionTypeInfoFactoryImpl.getTypeInfo(IntrospectionTypeInfoFactoryImpl.java:344) at org.jboss.reflect.plugins.introspection.IntrospectionTypeInfoFactory.getTypeInfo(IntrospectionTypeInfoFactory.java:54) at org.jboss.reflect.plugins.ArrayInfoImpl.getType(ArrayInfoImpl.java:99) (中略) SKIPPED CONFIGURATION: @BeforeClass setupClass SKIPPED CONFIGURATION: @BeforeMethod begin SKIPPED CONFIGURATION: @AfterMethod end SKIPPED CONFIGURATION: @AfterClass cleanupClass SKIPPED: testLogin
最終的に、VMパラメーターに-Dsun.lang.ClassLoader.allowArraySyntax=trueを追加することで、めでたく正常に動作可能になるようになりました。 最後の例外はJava6のJDKを利用している場合に発生するようです。
それにしても、SeamTestは埋め込みJBossを使っているのですが、これがなかなか曲者で正しく動作させるにはかなり苦労させられます。