I am relatively new to JAX-RS, JPA, GlassFish, Java DB and NetBeans, and I would like to write unit tests for my code. [Version numbers below.] However, I was stuck on where to start. I did a bit of work, but I donβt have a clear idea of ββhow to set up the built-in test of my code yet. I use NetBeans, but my question is general. I would like to formulate my question more clearly, but this is the best I could do. So far, I have found the following possible parts (more like hints at this point).
o I want to install this without Maven, but that means I have to install the built-in banks manually. Q: Where can I find them?
o Create versions of my xml configuration files (glassfish-resources.xml and persistence.xml) that specify the embedded versions of GlassFish and Java DB. Q: But how do you tell NetBeans to use them for testing, and not for production ones that rely on their installed version?
I think persistence.xml would look something like this (from using hibernate with a built-in derby ):
<property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.EmbeddedDriver"/> <property name="javax.persistence.jdbc.url" value="jdbc:derby:test"/> <property name="javax.persistence.jdbc.user" value="root"/> <property name="javax.persistence.jdbc.password" value="root"/>
o Create a custom Glassfish domain configuration file ( Embedded GlassFish ignores Maven test resources ). Question: What should it look like? I have domain.xml from the default domain1 that was created with my NetBeans installation, but there are a lot of things.
o As soon as my project gets access to embedded files and it is configured to use them, what does my JUnit look like? http://jersey.java.net/nonav/documentation/latest/client-api.html#d4e759 says:
protected void setUp() throws Exception { ... glassfish = new GlassFish(BASE_URI.getPort()); ScatteredWar war = new ScatteredWar(...); glassfish.deploy(war); ...
However, I also saw that EJBContainer mentioned, for example, (from http://docs.oracle.com/javaee/6/tutorial/doc/gkcqz.html ):
@BeforeClass public static void initContainer() throws Exception { ec = EJBContainer.createEJBContainer(); ctx = ec.getContext(); }
o I use JPA, so I need access to PersistenceContext / EntityManager. I am currently viewing it through:
new InitialContext().lookup("java:module/<jax-rs resource name>");
But I also saw:
emf = Persistence.createEntityManagerFactory("chapter02PU");
Q: What is the right way to get this?
I am very grateful for your help.
- Versions:
- GlassFish Server Open Source Edition 3.1.2 (Build 23)
- Java DB / Derby: 10.8.1.2 - (1095077)
- NetBeans IDE 7.1 (Build 201112071828)