Test Driven Development with   Java EE 7, Arquillian and    Enterprise Containers	            Peter Pilgrim	    Java Champ...
Biography ■  Completed Java Sybase course in 1998	 ■  Working as an Independent    Contractor 	 ■  Founded JAVAWUG 2004-20...
The Java EE 7 Developer User Guide           Written by Peter Pilgrim	            Late Summer 2013
Agile Software Development?
Why do we test?
Architectural Competencies    Performance and Efficiency	    Stability and Robustness	    Maintainability and Refactor-abil...
Tools of the Trade § Frameworks: JUnit, TestNG and XUnit; JBehave, Spock, ScalaTest 	 § Integrated Development Environme...
How do we test?
The Test Driven Cycle                                              Write A                                             Fai...
Essentials of Block Testing    Assign	      Act	     Assert
Traditional Java Enterprise Testing     Outside of the Container	      Mock and Stub objects	     Writing Tests around Dep...
Java EE 7
Java EE 7 Framework Updates Interface Boundary        Management and    Web and HTML      Endpoints     		    Storage	    ...
Time to Change JavaEE Testing
Open Source Integration Testing Peter Muir, David Blewin and Aslak Knutsen and from Red Hat JBoss.
Arquillian Test Framework    Portable In-Container Integration Testing	    Deployment of Unit Test and Dependencies togeth...
Shrink Wrap   An Aid to Better Test Enterprise Components	   “What if we could declare, in Java, an object to   represent ...
Context & Dependency Injection 1.1    Inject Beans in strongly typed manner	    Contextual Scopes, Qualifiers and Providers...
Gradle Dependencies I  dependencies {	     compile     org.jboss.spec.javax.annotation:jboss-annotations-api_1.2_spec:    ...
Gradle Dependencies II  dependencies {	     //...	     compile     javax:javaee-api:7.0-b81	     runtime     javax:javaee-...
Arquillian Test Structure I @RunWith(Arquillian.class)	 public class BasicUserDetailRepositoryTest {	     @Deployment	    ...
Arquillian Test Structure II @RunWith(Arquillian.class)	 public class BasicUserDetailRepositoryTest {     /* ... */	     @...
Demo: ArquillianContext Dependency & Injection
Enterprise Java Beans 3.2    Session Beans as Java Co-Located or Remote    Service Endpoints	    Transaction Support	    L...
Demo: ArquillianEnterprise Java Beans
HTML5 Java WebSocket 1.0   WebSocket connections are peer full-duplex   HTTP interactions over a session	   Reduced payloa...
Demo: ArquillianJava WebSocket API 1.0
Embeddable Containers   So-called “Container-less” Web Application	   Deliver an Container Embedded in Application	   You ...
GlassFish Embedded Initialization  public class AbstractEmbeddedRunner {	      private int port;	      private GlassFish g...
GlassFish Embedded Start and Stop  public class AbstractEmbeddedRunner {	     /* ... */	     public AbstractEmbeddedRunner...
GlassFish Embedded Deploy WAR  public class AbstractEmbeddedRunner {	     /* ... */	     public AbstractEmbeddedRunner dep...
Demo: GlassFish EmbeddedGlassFish 4.0 Embedded Server
Heavyweight vs. Lightweight   How on earth do you weigh 	  a Java container of any type?
Developer Summary
What You Will Do Tomorrow?                       Why                       Mock?	        Test    Philosophy	   CHANGE!	   ...
Resources § Arquillian Integration Server http://arquillian.org/	 § Java EE 7 Specification http://jcp.org/en/jsr/detail?...
Creative Commons Attributions §  Brett Lider, Folded Ruler, http://www.flickr.com/photos/brettlider/1575417754/sizes/o/in/...
Devoxx UK 2013 Test-Driven Development with JavaEE 7, Arquillian and Embedded Containers
Devoxx UK 2013 Test-Driven Development with JavaEE 7, Arquillian and Embedded Containers
Upcoming SlideShare
Loading in …5
×

Devoxx UK 2013 Test-Driven Development with JavaEE 7, Arquillian and Embedded Containers

3,434
-1

Published on

In this session, we introduce the Java developer to the Arquillian framework, Gradle and the Enterprise container technologies in Java EE 7. As a lucrative bonus we will cover building EJB and Java EE 7 tests applications with Gradle, the latest and greatest build framework for the Java platform, which improves on Apache Maven. The Java EE specification full contains three different containers, namely the Web, the EJB and the CDI containers. All of them can be reached using the Arquillian Framework, and this means there is now one general testing framework, which developers should learn as part of their professional duties. The session will cover writing meaningful tests for CDI, EJB and JAX-RS. Along the way, we will introduce new features of EJB 3.2, CDI 1.1 and RESTful Services. GlassFish Embedded Container 4.0 will be demonstrated.

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
3,434
On Slideshare
0
From Embeds
0
Number of Embeds
7
Actions
Shares
0
Downloads
30
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Devoxx UK 2013 Test-Driven Development with JavaEE 7, Arquillian and Embedded Containers

  1. 1. Test Driven Development with Java EE 7, Arquillian and Enterprise Containers Peter Pilgrim Java Champion, Software Developer Independent Contractor @peter_pilgrim
  2. 2. Biography ■  Completed Java Sybase course in 1998 ■  Working as an Independent Contractor ■  Founded JAVAWUG 2004-2010 ■  Blue-chip business and Banking: IT, Deutsche, Credit Suisse, UBS, Lloyds Banking 3
  3. 3. The Java EE 7 Developer User Guide Written by Peter Pilgrim Late Summer 2013
  4. 4. Agile Software Development?
  5. 5. Why do we test?
  6. 6. Architectural Competencies Performance and Efficiency Stability and Robustness Maintainability and Refactor-ability
  7. 7. Tools of the Trade § Frameworks: JUnit, TestNG and XUnit; JBehave, Spock, ScalaTest § Integrated Development Environment and Selenium
  8. 8. How do we test?
  9. 9. The Test Driven Cycle Write A Failing Test Ensure All Make The Tests Pass Test Pass Refactor the Refactor the Main Code Test "Oh, East is East, and West is West, and never the twain shall meet.”, Rudyard Kipling, 1892
  10. 10. Essentials of Block Testing Assign Act Assert
  11. 11. Traditional Java Enterprise Testing Outside of the Container Mock and Stub objects Writing Tests around Deployment
  12. 12. Java EE 7
  13. 13. Java EE 7 Framework Updates Interface Boundary Management and Web and HTML Endpoints Storage Service Endpoints JAX RS 2.0 EJB 3.2 Servlet 3.1 WebSocket 1.0 JMS 2.0 CDI 1.1 JSF 2.2 Bean Validation 1.1 JPA 2.1 JSON 1.0
  14. 14. Time to Change JavaEE Testing
  15. 15. Open Source Integration Testing Peter Muir, David Blewin and Aslak Knutsen and from Red Hat JBoss.
  16. 16. Arquillian Test Framework Portable In-Container Integration Testing Deployment of Unit Test and Dependencies together Extension of Existing Test Framework Support
  17. 17. Shrink Wrap An Aid to Better Test Enterprise Components “What if we could declare, in Java, an object to represent that archive?” Builder pattern for Virtual JAR file
  18. 18. Context & Dependency Injection 1.1 Inject Beans in strongly typed manner Contextual Scopes, Qualifiers and Providers Life-cycle, Event Management and Event Listeners
  19. 19. Gradle Dependencies I dependencies { compile org.jboss.spec.javax.annotation:jboss-annotations-api_1.2_spec: 1.0.0.Alpha1 compile org.jboss.spec.javax.ejb:jboss-ejb-api_3.2_spec:1.0.0.Alpha2 compile javax.enterprise:cdi-api:1.1-PFD’ compile javax.validation:validation-api:1.1.0.CR3 compile org.hibernate:hibernate-validator:5.0.0.CR4 compile org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Draft-14 runtime org.glassfish.main.extras:glassfish-embedded-all:4.0-b81’ testCompile org.jboss.arquillian.junit:arquillian-junit-container:1.0.3.Final testCompile org.jboss.arquillian.container:arquillian-glassfish- embedded-3.1:1.0.0.Final-SNAPSHOT testCompile junit:junit:4.11 }
  20. 20. Gradle Dependencies II dependencies { //... compile javax:javaee-api:7.0-b81 runtime javax:javaee-api:7.0-b81 //... testCompile junit:junit:4.11 }
  21. 21. Arquillian Test Structure I @RunWith(Arquillian.class) public class BasicUserDetailRepositoryTest { @Deployment public static JavaArchive createDeployment() { JavaArchive jar = ShrinkWrap.create(JavaArchive.class) .addClasses(BasicUserDetailRepository.class, UserDetailRepository.class, User.class) .addAsManifestResource( EmptyAsset.INSTANCE, "beans.xml"); return jar; } /* ... */ }
  22. 22. Arquillian Test Structure II @RunWith(Arquillian.class) public class BasicUserDetailRepositoryTest { /* ... */ @Inject private UserDetailRepository userDetailRepo; @Test public void shouldCreateUserInRepo() { User user = new User("frostj", "Jack", "Frost"); assertFalse( userDetailRepo.containsUser(user )); userDetailRepo.createUser(user); assertTrue( userDetailRepo.containsUser(user )); } }
  23. 23. Demo: ArquillianContext Dependency & Injection
  24. 24. Enterprise Java Beans 3.2 Session Beans as Java Co-Located or Remote Service Endpoints Transaction Support Lifecycle Event Management, Interception and Containment Endpoints Extended to Web Services, JAX-RS and/ or WebSockets
  25. 25. Demo: ArquillianEnterprise Java Beans
  26. 26. HTML5 Java WebSocket 1.0 WebSocket connections are peer full-duplex HTTP interactions over a session Reduced payload and lower latency Designed for asynchronous operations, performance and Efficiency
  27. 27. Demo: ArquillianJava WebSocket API 1.0
  28. 28. Embeddable Containers So-called “Container-less” Web Application Deliver an Container Embedded in Application You Have Control: Size, Framework and Libraries
  29. 29. GlassFish Embedded Initialization public class AbstractEmbeddedRunner { private int port; private GlassFish glassfish; public AbstractEmbeddedRunner init() throws Exception{ BootstrapProperties bootstrapProperties = new BootstrapProperties(); GlassFishRuntime glassfishRuntime = GlassFishRuntime.bootstrap(bootstrapProperties); GlassFishProperties glassfishProperties = new GlassFishProperties(); glassfishProperties.setPort("http-listener", port); // glassfishProperties.setPort("https-listener", port+1); glassfish = glassfishRuntime.newGlassFish(glassfishProperties); return this; } /* ... */ }
  30. 30. GlassFish Embedded Start and Stop public class AbstractEmbeddedRunner { /* ... */ public AbstractEmbeddedRunner start() throws Exception{ glassfish.start(); return this; } public AbstractEmbeddedRunner stop() throws Exception{ glassfish.stop(); return this; } /* ... */ }
  31. 31. GlassFish Embedded Deploy WAR public class AbstractEmbeddedRunner { /* ... */ public AbstractEmbeddedRunner deploy( String args[]) throws Exception{ Deployer deployer = glassfish.getDeployer(); for (String s: args) { String application = deployer.deploy(new File(s)); System.out.printf("deploying "+application); } return this; } /* ... */ }
  32. 32. Demo: GlassFish EmbeddedGlassFish 4.0 Embedded Server
  33. 33. Heavyweight vs. Lightweight How on earth do you weigh a Java container of any type?
  34. 34. Developer Summary
  35. 35. What You Will Do Tomorrow? Why Mock? Test Philosophy CHANGE! Arquillian Embedded Containers
  36. 36. Resources § Arquillian Integration Server http://arquillian.org/ § Java EE 7 Specification http://jcp.org/en/jsr/detail?id=342 § Java Web Socket API 1.0 http://java.net/projects/websocket-spec/downloads § GlassFish 4.0 Promoted Builds https://blogs.oracle.com/theaquarium/entry/ downloading_latest_glassfish_4_promoted § WebSocket Client http://www.websocket.org/echo.html § GlassFish Embedded Instructions http://embedded-glassfish.java.net/ § Thanks!
  37. 37. Creative Commons Attributions §  Brett Lider, Folded Ruler, http://www.flickr.com/photos/brettlider/1575417754/sizes/o/in/ photostream/ §  Daquella manera, Crutches donation to Haitian brothers and sisters, http://www.flickr.com/ photos/daquellamanera/4390506017/sizes/l/in/photostream/ §  Marcus Tschiae, Electric Power Framework perspective http://www.flickr.com/photos/tschiae/ 8417927326/sizes/h/ §  Falk Neumman, September 5, 2005, You’ve Got A Fast Car, http://www.flickr.com/photos/ coreforce/5910961411/ §  Stuart Webster, London skies from Waterloo Bridge, http://www.flickr.com/photos/ stuartwebster/4192629903/sizes/o/
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×