Java Reference
In-Depth Information
it you want Arquillian to run the test. By doing this, you get access to the powerful features
that Arquillian has, like @Deployment .
The @Deployment annotation comes next, and this annotation belongs to Arquillian,
not JUnit. By having JUnit hand off execution of the test to Arquillian, you're able to
use these Arquillian-specific features in the test. @Deployment annotates the public
static JavaArchive createDeployment() method . You include the meth-
od's full signature here, because unlike the JUnit annotations, the @Deployment an-
notation expects the method to return an implementation of JavaArchive . Think of a
JavaArchive as an Arquillian representation of a JAR, EJB-JAR, WAR, or EAR. In
chapter 5 we discussed the structures of these Enterprise archives. In an Arquillian in-
tegration test, the method annotated with @Deployment is responsible for creating a
JavaArchive and putting inside of it the classes and resources ( .properties , .xml ,
and the like) that would typically be in your project's final artifact. Because chapter-
15-ejb is an EJB-JAR project and its final artifact is a .jar file, in the integration test you
specify JavaArchive.class as the type you're building. You add all classes from
the com.actionbazaar.ejb package and the com.actionbazaar.entity
package to the JavaArchive . You also add the persistence.xml file to the
JavaArchive for JPA. Once the archive is built, the method returns it to Arquillian.
Under the covers, after Arquillian gets the JavaArchive , it starts the embedded contain-
er you've chosen to use (in this case you configured the GlassFish implementation) and
deploys the JavaArchive to the container. Remember, JavaArchive is an abstrac-
tion. In this integration test you built an EJB-JAR, but you can also build a plain-old JAR,
WAR, RAR, or EAR. Because Arquillian is running the container, your integration test can
take advantage of Java EE technologies. You see this in the test with the use of the @EJB
annotation to inject the MemberManager , MembershipLevelManager , and Dis-
countManager EJBs . Contrast this with the JNDI lookups needed for the embedded
EJBContainer integration tests. Developers can concentrate more on the test itself in-
stead of getting JNDI lookups to work. The Arquillian integration test is easier to under-
stand and more streamlined because it can take advantage of these advanced Java techno-
logies. After the Arquillian has started the embedded container and performed any depend-
ency injection on the test class, it's ready to run your tests—well, almost. Before the tests
can run, the JUnit lifecycle methods must still be run.
Search WWH ::




Custom Search