<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-6690261799654903311</id><updated>2012-02-16T03:15:10.193-08:00</updated><category term='netbeans maven unit-testing embedded ejb3.1 glassfish'/><title type='text'>undefined is not a function</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://pschyska.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6690261799654903311/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://pschyska.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Paul Schyska</name><uri>http://www.blogger.com/profile/05473572668746690922</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='http://1.bp.blogspot.com/_-UDOv_8lLms/TUlP1kNTAMI/AAAAAAAAABw/tENbaSNnMCQ/s220/web.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>2</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-6690261799654903311.post-2970495911605311364</id><published>2011-06-05T04:15:00.000-07:00</published><updated>2011-07-27T04:11:34.163-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='netbeans maven unit-testing embedded ejb3.1 glassfish'/><title type='text'>Unit-Testing EJB 3.1 with Netbeans, Maven and embedded Glassfish</title><content type='html'>When trying out unit-testing support in Netbeans 7.0 with the EJB 3.1 embedded container from glassfish 3.1 I ran across a few problems for which I want to share my solutions. I'm working through chapter 6 of "&lt;a href="http://www.apress.com/9781430228899"&gt;Beginning Java EE 6 with GlassFish 3&lt;/a&gt;"&amp;nbsp;at the moment. It's a good book but the code examples are not quite complete in some cases.&lt;br /&gt;&lt;br /&gt;I'm in an Maven EJB Module-Project in Netbeans using:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Netbeans 7.0&lt;/li&gt;&lt;li&gt;GlassFish Server Open Source Edition 3.1 (43)&lt;/li&gt;&lt;li&gt;maven 3.0.3 (bundled)&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;The module is just a scaffold consisting of:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;A JPA entity bean (provider: Eclipselink 2.0.2, jdbc: Derby 10.6.2.1 client)&lt;/li&gt;&lt;li&gt;An EJB implementing CRUD on this bean&lt;/li&gt;&lt;li&gt;A remote interface for the EJB&lt;/li&gt;&lt;li&gt;A web service&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;My goal is to test the EJB with the EJB 3.1 embedded container&lt;br /&gt;&lt;code style="font-size: smaller;"&gt;&lt;br /&gt;EJBContainer.createEJBContainer()&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;First of all, when you generate an unit test for the EJB in Netbeans and use the provided quick fix for missing EJBContainer, it modifies the pom.xml to use the so-called Glassfish static shell for the embedded container.&lt;br /&gt;&lt;code style="font-size: smaller;"&gt;&lt;br /&gt;&amp;lt;dependency&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;lt;groupId&amp;gt;org.glassfish.extras&amp;lt;/groupId&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;lt;artifactId&amp;gt;glassfish-embedded-static-shell&amp;lt;/artifactId&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;lt;version&amp;gt;3.1&amp;lt;/version&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;lt;scope&amp;gt;system&amp;lt;/scope&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;lt;systemPath&amp;gt;${glassfish.embedded-static-shell.jar}&amp;lt;/systemPath&amp;gt;&lt;br /&gt;&amp;lt;/dependency&amp;gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;It then sets the property ${glassfish.embedded-static-shell.jar} to a Glassfish installation of your choice, for example the bundled one. The jar file contains nothing but classpath entries for the jars needed for Glassfish embedded. This is suboptimal, as the build is now dependent on&amp;nbsp;a local installation in the right version, and is not portable due to the hard-code path in the property. When using Hudson or similar CI, having to have a Glassfish installation on your build server is sometimes not preferable.&lt;br /&gt;&lt;br /&gt;Alternatively, you can specify to download an embedded glassfish installation with the following pom.xml snippet:&lt;br /&gt;&lt;code style="font-size: smaller;"&gt;&lt;br /&gt;&amp;lt;dependency&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;lt;groupId&amp;gt;org.glassfish.extras&amp;lt;/groupId&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;lt;artifactId&amp;gt;glassfish-embedded-all&amp;lt;/artifactId&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;lt;version&amp;gt;3.1&amp;lt;/version&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;lt;scope&amp;gt;test&amp;lt;/scope&amp;gt;&lt;br /&gt;&amp;lt;/dependency&amp;gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Warning: This is a big download, around 70 MB.&lt;br /&gt;&lt;br /&gt;It works out of the box for simple EJB, but I still had a few issues in my case:&lt;br /&gt;&lt;ol&gt;&lt;li&gt;As soon as you put a remote interface in your bean, the embedded glassfish container starts a CORBA IIOP listener on default port 3700, resulting in a&amp;nbsp;BindException: Address already in use if there is another instance of glassfish running&lt;/li&gt;&lt;li&gt;As soon as you put a JAX-WS web service in your bean, the embedded container throws a&amp;nbsp;java.lang.NullPointerException at java.util.PropertyResourceBundle.handleGetObject(PropertyResourceBundle.java:136)&lt;/li&gt;&lt;li&gt;The embedded container can't find your JTA jdbc resources referenced in persistence.xml. I also wanted to use a different persistence.xml using an embedded Derby database and using drop-and-create for&amp;nbsp;eclipselink.ddl-generation&lt;/li&gt;&lt;/ol&gt;&lt;div&gt;To solve issue 1, I needed to use a different domain.xml than the default one for the embedded container to change the port numbers. Pointing the embedded container to a different domain.xml by putting the property&amp;nbsp;org.glassfish.ejb.embedded.glassfish.configuration.file in a map and passing it to&amp;nbsp;EJBContainer.createEJBContainer() as indicated by the&amp;nbsp;&lt;a href="http://download.oracle.com/docs/cd/E18930_01/html/821-2424/gjlde.html"&gt;Oracle GlassFish Server 3.1 Embedded Server Guide&lt;/a&gt; didn't work for me. Instead i had to use the org.glassfish.ejb.embedded.glassfish.instance.root, and point it to a glassfish domain directory. I have created it under src/test/resources/testing-domain. The following files are needed:&lt;/div&gt;&lt;div&gt;&lt;ul&gt;&lt;li&gt;config/admin-keyfile&lt;/li&gt;&lt;li&gt;config/cacerts.jks&lt;/li&gt;&lt;li&gt;config/domain.xml&lt;/li&gt;&lt;li&gt;config/keyfile&lt;/li&gt;&lt;li&gt;config/keystore.jks&lt;/li&gt;&lt;li&gt;config/login.conf&lt;/li&gt;&lt;li&gt;config/server.policy&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;I pulled the files from the&amp;nbsp;glassfish-embedded-all-3.1.jar and changed to domain.xml to use different port. I also activated the http and https listeners (putting them on ports 28080 and 28181, respectiveley).&lt;br /&gt;&lt;br /&gt;To solve issue 2, I had to put the property&amp;nbsp;org.glassfish.ejb.embedded.glassfish.web.http.port when calling&amp;nbsp;EJBContainer.createEJBContainer(props);&lt;br /&gt;The name of the property is a bit misleading, as the value is ignored completely and can be an empty String. It just means that the embedded glassfish instance should start the http listeners (just putting them as enabled="true" in domain.xml wasn't enough).&lt;br /&gt;&lt;br /&gt;To solve issue 3, I created an additional persistence.xml and put it to src/test/resources/META-INF:&lt;br /&gt;&lt;code style="font-size: smaller;"&gt;&lt;br /&gt;&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt; &lt;br /&gt;&amp;lt;persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"&amp;gt; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;lt;persistence-unit name="bookstore-ejb" transaction-type="JTA"&amp;gt; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;provider&amp;gt;org.eclipse.persistence.jpa.PersistenceProvider&amp;lt;/provider&amp;gt; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;exclude-unlisted-classes&amp;gt;false&amp;lt;/exclude-unlisted-classes&amp;gt; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;properties&amp;gt; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;property &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;name="eclipselink.target-database" &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;value="DERBY" /&amp;gt; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;property &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;name="eclipselink.ddl-generation" &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;value="drop-and-create-tables" /&amp;gt; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;property &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;name="eclipselink.logging.level" &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;value="FINE" /&amp;gt; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;property &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;name="javax.persistence.jdbc.driver" &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;value="org.apache.derby.jdbc.EmbeddedDriver" /&amp;gt; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;property &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;name="javax.persistence.jdbc.url" &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;value="jdbc:derby:memory:bookstore-ejb;create=true;" /&amp;gt; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;property &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;name="javax.persistence.jdbc.user" &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;value="APP" /&amp;gt; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;property &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;name="javax.persistence.jdbc.password" &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;value="APP" /&amp;gt; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/properties&amp;gt; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;lt;/persistence-unit&amp;gt; &lt;br /&gt;&amp;lt;/persistence&amp;gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Next, I copy target/classes to target/embedded-classes and afterwards copy target/test-classes to target/embedded-classes to overwrite my production META-INF/persistence.xml with the maven-resources-plugin:&lt;br /&gt;&lt;code style="font-size: smaller;"&gt;&lt;br /&gt;&amp;lt;plugin&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;artifactId&amp;gt;maven-resources-plugin&amp;lt;/artifactId&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;version&amp;gt;2.5&amp;lt;/version&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;executions&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;execution&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;id&amp;gt;copy-classes-to-embedded&amp;lt;/id&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;phase&amp;gt;compile&amp;lt;/phase&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;goals&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;goal&amp;gt;copy-resources&amp;lt;/goal&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/goals&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;configuration&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;outputDirectory&amp;gt;target/embedded-classes&amp;lt;/outputDirectory&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;overwrite&amp;gt;true&amp;lt;/overwrite&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;resources&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;resource&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;directory&amp;gt;target/classes&amp;lt;/directory&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/resource&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;resource&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;directory&amp;gt;src/test/resources&amp;lt;/directory&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/resource&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/resources&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/configuration&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/execution&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/executions&amp;gt;&lt;br /&gt;&amp;lt;/plugin&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;/plugins&amp;gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;&lt;div&gt;Then, I point the EJBContainer.MODULES property to target/embedded-classes.&lt;/div&gt;&lt;br /&gt;We can now write our unit-test like this:&lt;br /&gt;&lt;code style="font-size: smaller;"&gt;&lt;br /&gt;public class BookEJBTest { &lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private static EJBContainer ec=null; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private static Context ctx=null; &lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public BookEJBTest() { &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;} &lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;@BeforeClass &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public static void initContainer() throws Exception { &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Map&amp;lt;String, Object&amp;gt; props=new HashMap&amp;lt;String, Object&amp;gt;(); &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;props.put(EJBContainer.MODULES, new File("target/embedded-classes")); &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;props.put("org.glassfish.ejb.embedded.glassfish.instance.root","./src/test/testing-domain"); &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;props.put("org.glassfish.ejb.embedded.glassfish.web.http.port",""); &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ec = EJBContainer.createEJBContainer(props); &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ctx = ec.getContext(); &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;} &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;@AfterClass &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public static void closeContainer() throws Exception { &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if(ctx!=null) &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ctx.close(); &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if(ec!=null) &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ec.close(); &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;} &lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;@Test &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public void shouldCreateABook() throws Exception { &lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Book book = new Book(); &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;book.setTitle("The Hitchhiker's Guide to the Galaxy"); &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;book.setPrice(12.5F); &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;book.setDescription("Scifi book created by Douglas Adams"); &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;book.setIsbn("1-84023-742-2"); &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;book.setNbOfPages(354); &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;book.setIllustrations(false); &lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;BookEJB bookEJB = (BookEJB) ctx.lookup("java:global/embedded-classes/BookEJB!de.familienservice.bookstoreejb.BookEJB"); &lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;book = bookEJB.createBook(book); &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;assertNotNull("ID should not be null", book.getId()); &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;} &lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;The test runs with mvn test as well as with the embedded test runner in Netbeans 7.0. The build is portable und should run in my Hudson now.&lt;br /&gt;Note that I didn't create a test for the webservice yet. The URL the webservice binds to is always http://localhost:28080/... though, so this should be an easy task.&lt;br /&gt;&lt;br /&gt;FYR, I have put up the code for this project on &lt;a href="https://github.com/pschyska/embedded-glassfish-example"&gt;github&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;If you have any questions or tips for me, feel free to comment :-)&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Edit: You have to have the glassfish maven repository in addition to the eclipselink repository in your pom.xml&lt;/b&gt;&lt;br /&gt;&lt;pre  style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(http://2.bp.blogspot.com/_z5ltvMQPaa8/SjJXr_U2YBI/AAAAAAAAAAM/46OqEP32CJ8/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"&gt;&lt;code style="color:#000000;word-wrap:normal;"&gt;   &amp;lt;repositories&amp;gt;  &lt;br /&gt;     &amp;lt;repository&amp;gt;  &lt;br /&gt;       &amp;lt;url&amp;gt;http://ftp.ing.umu.se/mirror/eclipse/rt/eclipselink/maven.repo&amp;lt;/url&amp;gt;  &lt;br /&gt;       &amp;lt;id&amp;gt;eclipselink&amp;lt;/id&amp;gt;  &lt;br /&gt;       &amp;lt;layout&amp;gt;default&amp;lt;/layout&amp;gt;  &lt;br /&gt;       &amp;lt;name&amp;gt;Repository for library Library[eclipselink]&amp;lt;/name&amp;gt;  &lt;br /&gt;     &amp;lt;/repository&amp;gt;  &lt;br /&gt;     &amp;lt;repository&amp;gt;  &lt;br /&gt;       &amp;lt;id&amp;gt;glassfish-repo&amp;lt;/id&amp;gt;  &lt;br /&gt;       &amp;lt;url&amp;gt;http://download.java.net/maven/glassfish/&amp;lt;/url&amp;gt;  &lt;br /&gt;       &amp;lt;name&amp;gt;Repository for glassfish artifacts&amp;lt;/name&amp;gt;  &lt;br /&gt;     &amp;lt;/repository&amp;gt;  &lt;br /&gt;   &amp;lt;/repositories&amp;gt;  &lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6690261799654903311-2970495911605311364?l=pschyska.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://pschyska.blogspot.com/feeds/2970495911605311364/comments/default' title='Kommentare zum Post'/><link rel='replies' type='text/html' href='http://pschyska.blogspot.com/2011/06/unit-testing-ejb-31-with-netbeans-maven.html#comment-form' title='14 Kommentare'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6690261799654903311/posts/default/2970495911605311364'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6690261799654903311/posts/default/2970495911605311364'/><link rel='alternate' type='text/html' href='http://pschyska.blogspot.com/2011/06/unit-testing-ejb-31-with-netbeans-maven.html' title='Unit-Testing EJB 3.1 with Netbeans, Maven and embedded Glassfish'/><author><name>Paul Schyska</name><uri>http://www.blogger.com/profile/05473572668746690922</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='http://1.bp.blogspot.com/_-UDOv_8lLms/TUlP1kNTAMI/AAAAAAAAABw/tENbaSNnMCQ/s220/web.jpg'/></author><thr:total>14</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6690261799654903311.post-5704939883016155864</id><published>2011-02-04T03:36:00.000-08:00</published><updated>2011-02-04T03:57:54.551-08:00</updated><title type='text'>Introducing Ext.direct to Netzke</title><content type='html'>Ext.direct is a Sencha &lt;a href="http://www.sencha.com/products/extjs/"&gt;Ext JS&lt;/a&gt; standard API for communication with a &amp;nbsp;server. The spec defines a protocol and expected behavior for server-side implementation. On the client-side, there are three adaptors making use of this API: the Ext.direct.RemotingProvider for doing RPC, the Ext.direct.PollingProvider for doing server-side push functionality and&amp;nbsp;Ext.direct.JsonProvider for simple JSON APIs. There are also plans to implement a long-polling provider by the community, and I can imagine someone would want to write a &lt;a href="http://dev.w3.org/html5/websockets/"&gt;WebSockets&lt;/a&gt;-based provider for server push in the future.&lt;br /&gt;My work on&amp;nbsp;&lt;a href="http://netzke.org/"&gt;Netzke&lt;/a&gt;s&amp;nbsp;&lt;a href="https://github.com/pschyska/netzke-core"&gt;netzke-core&lt;/a&gt; (direct branch) changes the mechanism to make endpoint-RPC to a Ext.direct.RemotingProvider-based solution, completely preserving the API for endpoint calls.&lt;br /&gt;This has multiple advantages:&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Multiplexing/batching of RPC requests and responses&lt;/b&gt;&lt;br /&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;This is the main reason I thought Ext.direct could be useful for Netzke. While developing our application, we noticed that there is always a trade-off to be made between clean component-oriented design and technical considerations.&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;Technically, it is very bad to make multiple HTTP requests to the server for a single user action for obvious reasons.&lt;br /&gt;Now imagine an action is invoked in the client which causes (server-side) state-changes for multiple components, like needing to refresh two GridPanels at once. From a purely component-oriented standpoint, every component should be completely encapsulated in a way that only the component needs to know what to do on the server for a specific action. For example, I want the GridPanel to reload its data and the component handles the server communication transparent to the caller, because it is an implementation detail of the component. Now in our scenario, this would result in to two requests, because I tell two GridPanels to reload the data, and let them handle it (also, it's very possible that they are customized and have some slightly different ways to achieve the reloading).&lt;br /&gt;However, to solve the technical requirement "only one HTTP request per user action" the caller can't use this approach. Instead, it needs to send the server a special message "reload these two GridPanels", needs to dispatch the requests to the GridPanels on the server side, collect the results and afterwards dispatch the response to the client-side components. For this, it needs to know some implementation details of the GridPanels, which is contradictory to the principle of encapsulation in an component-oriented/OOP approach.&lt;br /&gt;The multiplexing feature of Ext.direct solves this issue. With it, components can make endpoint calls which will get collected within a configurable timeframe (default: 10ms), and sent in a batch in a single HTTP requests to the server, preserving the order of the calls. The server can then dispatch the single requests and collect the result, and send a single response with the batched results, again in the order the original requests will be made. Ext.direct also handles the dispatching on the client side.&lt;br /&gt;This allows us now to keep our components strictly encapsulated and make as many requests to the server from within the components as we want, without needing to check if some other component in the current composition also makes requests.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Fault-tolerance and tracking of transactions&lt;/b&gt;&lt;br /&gt;&lt;b&gt;&lt;/b&gt;Ext.direct assigns an transaction id per RPC and expects the server to include the transaction id in responses. This way the Ext.direct client can track ongoing transactions, can time the connections out in a controlled way (default timeout: 30s) and can retry the transaction in case of a packet loss or server fault (defaults to 3 attempts). Future improvement could be the tracking of transaction id on the server side, to make sure every transaction get's only executed once to prevent accidental multiple mutations of server state in case only the response gets lost on the wire. I haven't found a solution for this that doesn't involve an ever-growing list of transaction ids already processed that would make the heap explode eventually :-)&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Possible extension point for future functionality&lt;/b&gt;&lt;br /&gt;&lt;b&gt;&lt;/b&gt;There is other functionality possible with Ext.direct, like the already mentioned server push mechanisms.&amp;nbsp;I'm also in anticipation to see a long-polling or WebSockets implementation for Ext.direct.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Drawbacks&lt;/b&gt;&lt;br /&gt;&lt;b&gt;&lt;/b&gt;However, the current mechanism involving directly passing an endpointUrl() to Ext components won't work any more. Good news is, every component that takes an url: config (like stores) can be rewritten to use api: or directFn: configuration pointing to the generated endpoint (or can be replaced by specialized components like DirectStore).&lt;br /&gt;I suggest that endpointUrl will be deprecated (the old way of accessing endpoints will still work, but won't benefit from Ext.direct).&lt;br /&gt;I already modified&amp;nbsp;&lt;a href="https://github.com/pschyska/netzke-basepack"&gt;netzke-basepack&lt;/a&gt;&amp;nbsp;(also in direct branch) to make use of the Ext.direct provider in GridPanel, FormPanel, PagingFormPanel and Combobox. These are all places in basepack where endpointUrl was used. You should check the related changes in basepack and do them for your own app.&lt;br /&gt;&lt;br /&gt;The current state of my work is "almost finished". It's passing the current netzke-core and netzke-basepack cucumber test-suites, but is missing tests for the specific Ext.direct functions (batching, controlled timeout and retry). Also it's missing configuration for delay timeframe of requests, timeout and retry count. In the end, it wasn't a lot of change but with considerable advantages (IMHO).&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Demo&lt;/b&gt;&lt;br /&gt;&lt;b&gt;&lt;/b&gt;I have put together a small demo showing automatic request batching. It consists of two GridPanels and a single action, which adds a row to each of them. First, I show how it looks like in the current master branch. Then, I check out my direct branch and do the test again, and the number of requests is decreased.&lt;br /&gt;&lt;br /&gt;&lt;iframe src="http://player.vimeo.com/video/19560047" width="400" height="300" frameborder="0"&gt;&lt;/iframe&gt;&lt;p&gt;&lt;a href="http://vimeo.com/19560047"&gt;Demo: Ext.direct in Netzke&lt;/a&gt; from &lt;a href="http://vimeo.com/pschyska"&gt;Paul Schyska&lt;/a&gt; on &lt;a href="http://vimeo.com"&gt;Vimeo&lt;/a&gt;.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;I appreciate any comments and suggestions, and feel free to fork me on &lt;a href="https://github.com/pschyska"&gt;github&lt;/a&gt; and follow me on &lt;a href="http://twitter.com/pschyska"&gt;Twitter&lt;/a&gt;&amp;nbsp;&amp;nbsp;:-)&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6690261799654903311-5704939883016155864?l=pschyska.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://pschyska.blogspot.com/feeds/5704939883016155864/comments/default' title='Kommentare zum Post'/><link rel='replies' type='text/html' href='http://pschyska.blogspot.com/2011/02/introducing-extdirect-to-netzke.html#comment-form' title='0 Kommentare'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6690261799654903311/posts/default/5704939883016155864'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6690261799654903311/posts/default/5704939883016155864'/><link rel='alternate' type='text/html' href='http://pschyska.blogspot.com/2011/02/introducing-extdirect-to-netzke.html' title='Introducing Ext.direct to Netzke'/><author><name>Paul Schyska</name><uri>http://www.blogger.com/profile/05473572668746690922</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='http://1.bp.blogspot.com/_-UDOv_8lLms/TUlP1kNTAMI/AAAAAAAAABw/tENbaSNnMCQ/s220/web.jpg'/></author><thr:total>0</thr:total></entry></feed>
