NetBeans 7.0、JUnit 和 Glassfish Embedded 3.1:不起作用

发布于 2024-11-17 01:57:18 字数 4378 浏览 1 评论 0原文

我正在尝试在 Win7Professional 机器中使用 NB 7.0、JUnit 和嵌入式 Glassfish 服务器进行 JUnit 测试 J2EE Web 应用程序。

我将其分解为使用单个会话 Bean 来测试一个简单的 Hello-World Web 应用程序。

我的类路径中有 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 两次,但它也不起作用。

I am trying to JUnit Test a J2EE Web Application with NB 7.0, JUnit and the embedded Glassfish Server in a Win7Professional machine.

I broke it down to just test a plain simple Hello-World Web App with a single Session Bean.

I have the glasfish-embedded-static-shell.jar in my classpath, and also tried to use the glassfish-embedded-all-3.1 but it also didn't work.

Now here's the code I use to test the 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);

}
}

And here's what comes out of it:

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.

UPDATE:
And this is the exception which would be thrown by any test:

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

I have reinstalled NetBeans twice and it doesn't works either.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

怪我闹别瞎闹 2024-11-24 01:57:18

我遇到了同样的问题,我执行了以下操作:

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 中,我删除其他人说我必须的依赖项如果我收到错误“提供商已映射...”,请添加

<dependency>
    <groupId>org.glassfish.extras</groupId>
    <artifactId>glassfish-embedded-all</artifactId>
    <version>3.1.1</version>
    <scope>test</scope>
</dependency>

它!现在,我使用 JPA 2 进行的 EJB JUnit 测试工作得非常顺利!希望这有帮助!

I had the same issue and I did the following:

1) I installed Glassfish 3.1.1 and linked it to my project. First I added the server with Tools - Servers - Add Server... Then I right-clicked my EJB project and selected Properties - Run - Glassfish 3.1.1
2) In my EJB pom.xml I use this dependency (make sure the systemPath variable points to the correct file):

<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) In my EJB pom.xml I removed the dependency other people said I have to add it if I get the errors "Provider already mapped..."

<dependency>
    <groupId>org.glassfish.extras</groupId>
    <artifactId>glassfish-embedded-all</artifactId>
    <version>3.1.1</version>
    <scope>test</scope>
</dependency>

That's it! Now my EJB JUnit tests with JPA 2 work like a charm! Hope this helps!

夕色琉璃 2024-11-24 01:57:18

似乎服务器启动正常(其中一些例外是预期的,但我无法确认是否全部例外)。

  • 您是否使用“运行>测试项目”运行测试用例?
  • JUnit GUI 是否弹出?
  • 是否安装了 JUnit?由于许可问题,Netbeans 7.0 现在询问您是否要下载 JUnit...
  • 您可以运行不需要嵌入式容器的单元测试吗?

尝试按照以下步骤操作: http://javadude.wordpress.com/2010/02/22/tutorial-most-simple-test-application-for-embedded-glassfish-netbeans-hudson/(忘记哈德逊部分)。 IDE 应该负责为您添加依赖项。

哦,另一件事,由于您使用的是 Windows,因此尝试以管理员身份运行 Netbeans(右键单击选项)并看看会发生什么情况不会有什么坏处。

干杯,

更新

也许您遇到了这个错误:

看看是否像这样启动容器对您有用:

@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);
}

Seems like the server is starting ok (some of those exceptions are expected, but I can't confirm if all of them are).

  • Are you running the tests cases with "Run > Test Project"?
  • Is the JUnit GUI popping up?
  • Is JUnit installed? Netbeans 7.0 now asks if you want to download JUnit because of licensing Issues...
  • Can you run unit tests that don't need the embedded container?

Try to follow those steps: http://javadude.wordpress.com/2010/02/22/tutorial-most-simple-test-application-for-embedded-glassfish-netbeans-hudson/ (forget about the Hudson part). The IDE should take care of including the dependencies for you.

Oh, another thing, since you are using Windows, it won't hurt to try to run Netbeans as Admin (right click option) and see what happens.

Cheers,

Update

Maybe you are hitting this bug:

See if starting the container like this works for you:

@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);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文