NetBeans 7.0,JUnit和Glassfish Embedded 3.1:不起作用
我正在尝试JUnit在Win7Professional机器上用NB 7.0,JUnit和嵌入式Glassfish服务器测试J2EE Web应用程序。
我把它分解成只用一个Session Bean测试一个简单的Hello-World Web App。
我的classpath中有glasfish-embedded-static-shell.jar,并试图使用glassfish-embedded-all-3.1,但它也不起作用。
这里是我用来测试bean的代码:
import javax.ejb.embeddable.EJBContainer;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;
public class SimpleBeanTest {
private static EJBContainer container;
public SimpleBeanTest() {
}
@BeforeClass
public static void setUpClass() throws Exception {
container = javax.ejb.embeddable.EJBContainer.createEJBContainer();
}
@AfterClass
public static void tearDownClass() throws Exception {
container.close();
}
@Test
public void testCountToThree() throws Exception {
System.out.println("countToThree");
SimpleBean instance = (SimpleBean) container.getContext().lookup("java:global/classes/SimpleBean");
int expResult = 0;
int result = instance.countToThree();
assertEquals(expResult, result);
}
}
以下是它的结果:
19.06.2011 09:31:56 com.sun.enterprise.v3.server.CommonClassLoaderServiceImpl findDerbyClient
INFO: Cannot find javadb client jar file, derby jdbc driver will not be available by default.
19.06.2011 09:31:56 org.glassfish.flashlight.impl.provider.FlashlightProbeProviderFactory processXMLProbeProviders
SCHWERWIEGEND: MNTG0301:Cannot process XML ProbeProvider, xml = META-INF/gfprobe-provider.xml
java.lang.IllegalStateException: Provider already mapped glassfish:javamail:smtp-transport
(StackTrace here)
19.06.2011 09:31:57 org.glassfish.flashlight.impl.provider.FlashlightProbeProviderFactory processXMLProbeProviders
SCHWERWIEGEND: MNTG0301:Cannot process XML ProbeProvider, xml = META-INF/mojarra-jsf-api-probe-provider.xml
java.lang.IllegalStateException: Provider already mapped glassfish:jsf:faces-servlet
(StackTrace here)
19.06.2011 09:31:57 org.glassfish.flashlight.impl.provider.FlashlightProbeProviderFactory processXMLProbeProviders
SCHWERWIEGEND: MNTG0301:Cannot process XML ProbeProvider, xml = jersey-gf-server-probe-provider.xml
java.lang.IllegalStateException: Provider already mapped glassfish:jersey:server-hidden
(StackTrace here)
19.06.2011 09:31:57 org.glassfish.flashlight.impl.provider.FlashlightProbeProviderFactory processXMLProbeProviders
SCHWERWIEGEND: MNTG0301:Cannot process XML ProbeProvider, xml = jersey-gf-statsprovider-probe-provider.xml
java.lang.IllegalStateException: Provider already mapped glassfish:jersey:server
(StackTrace here)
19.06.2011 09:31:57 org.glassfish.ha.store.spi.BackingStoreFactoryRegistry register
INFO: Registered org.glassfish.ha.store.adapter.cache.ShoalBackingStoreProxy for persistence-type = replicated in BackingStoreFactoryRegistry
19.06.2011 09:31:57 org.glassfish.ha.store.spi.BackingStoreFactoryRegistry register
INFO: Registered org.glassfish.ha.store.adapter.cache.ShoalBackingStoreProxy for persistence-type = replicated in BackingStoreFactoryRegistry
19.06.2011 09:31:57 com.sun.enterprise.v3.server.AppServerStartup run
SCHWERWIEGEND: Startdienst konnte nicht gestartet werden: com.sun.enterprise.naming.GlassFishNamingBuilder
19.06.2011 09:31:57 com.sun.enterprise.v3.server.AppServerStartup run
INFO: GlassFish Server Open Source Edition 3.1 (43) Startzeit: Embedded (597ms), Startdienste(929ms), gesamt(1.526ms)
19.06.2011 09:31:57 org.glassfish.admin.mbeanserver.JMXStartupService$JMXConnectorsStarterThread run
INFO: JMXStartupService: JMXConnector system is disabled, skipping.
更新:这是任何测试会抛出的异常:
No EJBContainer provider available
Provider named org.glassfish.ejb.embedded.EJBContainerProviderImpl threw unexpected exception at create EJBContainer:
java.lang.RuntimeException
java.lang.RuntimeException: java.lang.IllegalStateException: AMX Booter MBean is already registered: amx-support:type=boot-amx
at org.glassfish.internal.embedded.Server.<init>(Server.java:290)
at org.glassfish.internal.embedded.Server.<init>(Server.java:66)
at org.glassfish.internal.embedded.Server$Builder.build(Server.java:176)
(Stack Trace here)
Caused by: java.lang.IllegalStateException: AMX Booter MBean is already registered: amx-support:type=boot-amx
我重新安装了NetBeans两次,它也不起作用。
我有同样的问题,我做了以下几点:
1)我安装了Glassfish 3.1.1并将其链接到我的项目。 首先,我添加了服务器工具 - 服务器 - 添加服务器...然后我右键单击我的EJB项目并选择属性 - 运行 - Glassfish 3.1.1
2)在我的EJB pom.xml中,我使用这种依赖关系(确保systemPath变量指向正确的文件):
<dependency>
<groupId>org.glassfish.extras</groupId>
<artifactId>glassfish-embedded-static-shell</artifactId>
<version>3.1.1</version>
<scope>system</scope>
<systemPath>${glassfish.embedded-static-shell.jar}</systemPath>
</dependency>
3)在我的EJB pom.xml中,我删除了其他人说我必须添加它的依赖项,如果我得到错误“Provider already mapped ...”
<dependency>
<groupId>org.glassfish.extras</groupId>
<artifactId>glassfish-embedded-all</artifactId>
<version>3.1.1</version>
<scope>test</scope>
</dependency>
而已! 现在我的EJB JUnit测试JPA 2就像一个魅力! 希望这可以帮助!
似乎服务器开始正常(预计会有一些例外,但我不能确认它们是否都是)。
尝试遵循以下步骤:http://javadude.wordpress.com/2010/02/22/tutorial-most-simple-test-application-for-embedded-glassfish-netbeans-hudson/(忘记哈德森部分)。 IDE应该照顾为您提供依赖关系。
哦,另一件事,因为你使用的是Windows,所以尝试以管理员身份运行Netbeans(右键单击选项)并查看会发生什么并不会有什么影响。
干杯,
更新
也许你正在碰到这个bug:
看看这样的容器是否适合你:
@BeforeClass
public static void setUpClass() throws Exception {
Map<String, Object> p = new HashMap<String, Object>();
p.put(EJBContainer.APP_NAME, "foo");
container = EJBContainer.createEJBContainer(p);
}
链接地址: http://www.djcxy.com/p/53335.html
上一篇: NetBeans 7.0 , JUnit and Glassfish Embedded 3.1: Does not work
下一篇: Retrieving additional data from already loaded Magento models