NetBeans 7.0, JUnit, and Glasfish Embedded 3.1: not working

I am trying JUnit to test a J2EE web application with NB 7.0, JUnit and the built-in Glassfish server on a Win7Professional machine.

I broke it to just test a simple simple Hello-World web application with a single Bean session.

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

Now here is 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 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 an exception that 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 re-installed NetBeans twice and it also does not work.

+6
source share
2 answers

I had the same problem and I did the following:

1) I installed Glassfish 3.1.1 and linked it to my project. First I added the server using 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 that other people said that I should add it if I get the error "The provider is already mapped ..."

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

What is it! Now my EJB JUnit tests with JPA 2 work like a charm! Hope this helps!

+3
source

It seems that the server is starting normally (some of these exceptions are expected, but I cannot confirm if they are all).

  • Do you run tests with Run> Test Project?
  • Does JUnit GUI appear?
  • Is JUnit installed? Netbeans 7.0 now asks if you want to download JUnit due to licensing issues ...
  • Can you run unit tests that don't need an inline container?

Try the following 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 to include dependencies.

Oh, one more thing, since you are using Windows, it doesn’t hurt to try running Netbeans as an administrator (right-click) and see what happens.

Greetings

Update

Perhaps you will click this bug:

See if this container 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); } 
+1
source

Source: https://habr.com/ru/post/891358/


All Articles