Testing your DAO’s with Java

Slides:



Advertisements
Similar presentations
Java EE - Introduction -
Advertisements

Enterprise Java and Data Services Designing for Broadly Available Grid Data Access Services.
J2EE Architecture Overview
Persistence Jim Briggs 1. 2 Database connectivity: JDBC Java Database Connectivity An API for connecting Java programs (applications, applets and servlets)
ISE 390 Dynamic Web Development Java EE Web Applications.
Spring, Hibernate and Web Services 13 th September 2014.
Introduction to Spring Matt Wheeler. Notes This is a training NOT a presentation Please ask questions Prerequisites – Introduction to Java Stack – Basic.
10/8/12http://free.smartbiz.vn1 JSR-299 CDI Java Contexts & Dependency Injection JBoss Weld Implementation.
JBoss Seam: Contextual Components Jason Bechtel
Presented by IBM developer Works ibm.com/developerworks/ 2006 January – April © 2006 IBM Corporation. Making the most of The Eclipse Web Tools Platform.
© 2005, Cornell University. Rapid Application Development using the Kuali Architecture (Struts, Spring and OJB) A Case Study Bryan Hutchinson
Pragmatic Application Building: Step by Step Jay Sissom Principal Systems Analyst Indiana University
Introduction to EJB INFORMATICS ENGINEERING – UNIVERSITY OF BRAWIJAYA Eriq Muhammad Adams J
Emmanuel Cecchet et al.  Performance Scalability of J2EE application servers.  Test effect of: ◦ Application Implementation Methods ◦ Container Design.
Introduction to Spring Matt Wheeler. Notes This is a training NOT a presentation Please ask questions Prerequisites – Introduction to Java Stack – Basic.
Spring Roo CS476 Aleksey Bukin Peter Lew. What is Roo? Productivity tool Allows for easy creation of Enterprise Java applications Runs alongside existing.
Introduction to JPA Java Persistence API Introduction to JPA.
Hibernatification! Roadmap for Migrating from Plain Old SQL on JDBC to JPA on Hibernate Duke Banerjee Senior Developer, DrillingInfo.com.
CSE446 S OFTWARE Q UALITY M ANAGEMENT Spring 2014 Yazılım ve Uyguluma Geliştirme Yöneticisi Orhan Başar Evren.
CSCI 6962: Server-side Design and Programming Course Introduction and Overview.
2007 JavaOne SM Conference | Session BOF-4181 | BOF-4181 Migrating a Spring/Hibernate Application to Java Platform, Enterprise Edition (Java EE) 5 Adrian.
Spring Overview, Application demo -Midhila Paineni 09/23/2011 Spring Overview, Application demo9/8/20151.
MAVEN-BLUEMARTINI Yannick Robin. What is maven-bluemartini?  maven-bluemartini is Maven archetypes for Blue Martini projects  Open source project on.
Ing. Ignacio Roqueta ARTech GeneXus and J2EE.
Enterprise Java Beans Part I Kyungmin Cho 2001/04/10.
Enterprise Java Bean Matt. 2 J2EE 3 J2EE Overview.
Spring core v3.x Prepared by: Nhan Le. History v3.0 Spring Expression Language Java based bean metadata v3.1 Cache Abstraction Bean Definition Profile.
JBoss at Work JAW Motors Application Chapter 1-3 Jeff Schmitt October 9, 2006.
JBoss Seam Presented by Andy Nguyen Truc Pham. What is JBoss Seam? Created by Gavin King Created by Gavin King A lightweight framework for Java EE 5.0.
Opus College - overview. OpusCollege - background First project: ICT Capacity Building Mozambican Higher Education Institutions Partners: RUG Groningen,
CHEF II / Sakai Architecture. CHEF II Changes uPortal replaces Jetspeed –jsr 168 portlet, servlet compliant Spring replaces Turbine component framework.
Spring Framework. Spring Overview Spring is an open source layered Java/J2EE application framework Created by Rod Johnson Based on book “Expert one-on-one.
Introduction to Spring Matt Wheeler. Notes This is a training NOT a presentation Please ask questions Prerequisites – Introduction to Java Stack – Basic.
Introduction to Web Dimitar Nenchev Ivan Nakov
Enterprise JavaBeans Understanding EJB Components Version 0.1 Kamal Wickramanayake
1 Apache TomEE // JavaEE Web Profile on Tomcat Jonathan #TomEE.
Spring Framework. About spring Spring is the most popular application development framework for enterprise Java. Millions of developers around the world.
Chính phủ điện tử TS. Phạm Văn Tính Khoa CNTT, ĐH Nông Lâm TP.HCM
Topic : Hibernate 1 Kaster Nurmukan. An ORM tool The problem fixed by ORM Advantage Hibernate Hibernate Basic –Hibernate sessionFactory –Hibernate Session.
Spring and DWR Frameworks for Rich Web Enterprise Application Thomas Wiradikusuma Presentation to the 20 th.
Jonathan Gallimore | Tomitribe Cluster your application with JCache and CDI.
1 Spring Framework April, 2012 Lam Ho Lam To. © 2010 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 2 1.Spring Overview 2.Framework.
Test it! Unit, mocking and in-container Meet Arquillian! Ivan St. Ivanov.
JAVA EE 6 Best Practices for Migrating Spring to WTF ?!?
Session Beans Based on: Patel, Brose, Silverman, Mastering Enterprise JavaBeans 3.0.
Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. Introduction to Data Access with Spring.
Java Programming: Advanced Topics 1 Enterprise JavaBeans Chapter 14.
Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. Overview of the Spring Framework Introducing.
Enterprise Java v JNDI Enterprise Naming Conext (ENC) and Injection JNDI ENC.
Singleton Academy, Pune. Course syllabus Singleton Academy Pune – Course Syllabus1.
EJB Enterprise Java Beans JAVA Enterprise Edition
1 Entity Callbacks and Listeners When you execute EntityManager methods like persist( ), merge( ), remove( ), and find( ), or when you execute EJB QL queries,
Google Code Libraries Dima Ionut Daniel. Contents What is Google Code? LDAPBeans Object-ldap-mapping Ldap-ODM Bug4j jOOR Rapa jongo Conclusion Bibliography.
Test Java EE applications with Arquillian Ivan St. Ivanov.
J AVA T RAINING IN A HMEDABAD By TOPS Technologies 1 TOPS Technologies Java Course.
CS520 Web Programming Spring – Web MVC Chengyu Sun California State University, Los Angeles.
Apache TomEE Tomcat with a kick. Apache TomEE: Overview ● Java EE 6 Web Profile certification in progress ● Apache TomEE Includes support for: ● Servlet.
Enterprise Java Beans. Contents  Understanding EJBs  Practice Section.
CS520 Web Programming Spring – Inversion of Control Chengyu Sun California State University, Los Angeles.
Oracle Java Cloud Service Oracle Develop July 2013.
Structure of a web application
CS520 Web Programming Spring – Inversion of Control
Java EE Overview The problem Java Enterprise Edition attempts to solve: maximize the use of Java technologies by providing a suite of Java technology specifications.
By Ru Shen Department of Computer Science UAlbany, 2008
Building an Integrable XBRL Portal Daniel Hamm German Central Bank
ISE 390 Dynamic Web Development
What’s changed in the Shibboleth 1.2 Origin
Java EE Overview The problem Java Enterprise Edition attempts to solve: maximize the use of Java technologies by providing a suite of Java technology specifications.
Testing a persistence layer
Developing and testing enterprise Java applications
Presentation transcript:

Testing your DAO’s with Java Rory Preddy

Agenda What we encounter Testing with JDBC CDI 101 Testing with CDI DeltaSpike Summary

What we encounter Entities or SQL DAO layer Service Layer (CDI, ManagedBean or EJB) Web layer Arquillian for testing Service with EJB’s Selenium on Web Layer No DAO testing

Why Test DAO? Persistence frameworks (JPA, JDO, etc) help but… Frameworks can be misconfigured Frameworks can be asked to do the wrong thing Incorrect mappings Cascade actions can be hell Physical DB’s are rarely in a sober state

What we encounter Testing with JDBC CDI 101 Testing with CDI Summary DeltaSpike Summary

Basic testing principles Create multiple databases In memory for local Physical for DEV/UAT Ensure the state of the database prior to testing Test in small chunks of data Don’t try to load everything into the database for a single test

Test with JDBC (demo) Maven build Create DB with Derby Tools Insert Base data with DBUnit Create a Connection Test CRUD Clean database

What we encounter Testing with JDBC CDI 101 Testing with CDI Summary DeltaSpike Summary

Content & Dependency Injection Inversion Of Control" object creation No more hardcoded dependencies Customer cs = new VerySpecialCustomer(); Basically the old Factory Pattern Hollywood Principle: “Don't call us, we call you!” Macho Principle “Dude, gimme that bloody stuff!” In CDI 1.0, you must add a beans.xml file to your archive Since CDI 1.1, it’s activated by default: All classes having a “bean defining annotation” become a bean You can still use beans.xml file to activate CDI explicitly ordeactivate it

Content & Dependency Injection Can we used in Standard Edition, Servlet or EJB containers Adds the Web conversation context + to standard contexts (request, session, application…) To activate CDI Create a beans.xml file (can be empty) Add maven dependencies In CDI 1.0, you must add a beans.xml file to your archive Since CDI 1.1, it’s activated by default: All classes having a “bean defining annotation” become a bean You can still use beans.xml file to activate CDI explicitly ordeactivate it

CDI history & actual state Main milestone : December 2009 : CDI 1.0 June 2013 : CDI 1.1 April 2014 : CDI 1.2 Q1 2016 : CDI 2.0 due Implementations : JBoss Weld (RI) : WildFly, JBoss EAP, Glassfish, Weblogic Apache OpenWebBeans : TomEE, Websphere Check http://cdi-spec.org

Dependency Injection @Inject

Dependency Injection public class HelloService { public String hello() { return "Hello World!"; }

Dependency Injection in Constructor public class MyBean { private HelloService service; @Inject public MyBean(HelloService service) { this.service = service; } public void displayHello() { display( service.hello();

Dependency Injection in setter public class MyBean { private HelloService service; @Inject public void setService(HelloService service) { this.service = service; } public void displayHello() { display( service.hello();

Dependency Injection in field public class MyBean { @Inject HelloService service; public void displayHello() { display( service.hello(); }

Qualifiers public interface HelloService { public String hello(); } public class AfrikaansHelloService implements HelloService { public String hello() { return "Howzit!"; public class EnglishHelloService implements HelloService { return "Hello World!";

Qualifiers @Qualifier @Retention(RUNTIME) @Target({FIELD, TYPE, METHOD, PARAMETER}) public @interface Afrikaans {} public @interface English {}

Qualifiers (declaring) @Afrikaans public class AfrikaansHelloService implements HelloService { public String hello() { return "Howzit!";} } @English public class EnglistHelloService implements HelloService { return “Hello world!";}

Qualifiers (assigning) public class MyBean { @Inject @Afrikaans HelloService service; public void displayHello() { display( service.hello(); } @Inject @English HelloService service;

Qualifiers with members @Retention(RUNTIME) @Target({FIELD, TYPE, METHOD, PARAMETER}) public @interface Language { Languages value(); @Nonbinding String description() default ""; public enum Languages { Afrikaans, ENGLISH }

Qualifiers (declaring) @Language(Afrikaans) public class AfrikaansHelloService implements HelloService { public String hello() { return "Howzit!"; } @Language(ENGLISH) public class EnglishHelloService implements HelloService { return "Hello World!"; }!

Qualifiers (assigning) public class MyBean { @Inject @Language(ENGLISH) HelloService service; public void displayHello() { display( service.hello(); } @Inject @Language(Afrikaans) HelloService service;

Reserved Qualifiers (filter) @Any – all beans, unless they have @New @Default, @Named (Filter) @New – forces the container to return a new bean instance each time @New public class SomeBean {..} public class AnotherBean { @Inject SomeBean bean1; @Inject SomeBean bean2; @PostConstruct void init() { log.info(bean1 == bean2); // false } ambiguous dependencies

Producers @Produces public MyNonCDIClass myProducer() { return new MyNonCdiClass(); } ... @Inject MyNonCDIClass bean;

Injecting EntityManager @Produces @Produces @PersistenceContext(unitName="CustomerDatabase") @CustomerDatabase EntityManager customerDatabasePersistenceContext; @inject @Inject @CustomerDatabase EntityManager myEntityManager Close public void close(@Disposes EntityManager em) { if (em.isOpen()) { em.close(); }

What we encounter Testing with JDBC CDI 101 Testing with CDI Summary DeltaSpike Summary

CDI Frameworks FRAMEWORK Who owns it Spring EMC (VMWARE) Guice Google Weld Redhat OpenWebBeans Apache Extension Who owns it DeltaSpike Apache

DeltaSpike? Seam 2.2 targets JBoss AS 5 and 6 as well as JBoss Enterprise Application Platform 5 - Java EE 5 based architecture Seam 2.3 targets Java EE 6 capabilities such as JSF2 and JPA2 on the JBoss Enterprise Application Platform 6 - Seam 2.3 also supports RichFaces 4 which is also available for commercial support via Web Framework Kit. If you are looking for the long-term support with a service level agreement of Seam 2.2 and/or Seam 2.3 then please contact us at http://www.redhat.com/contact/sales.html Seam 2.3 is part of Web Framework Kit, included as part of the JBoss Enterprise Application Platform subscription . Seam 2.3 was released in September 2012. This is an update to the Seam 2 code base to make it compatible with Jave EE 6. It runs well on JBoss AS 7. Seam 3 Active development of Seam 3 has been halted by Red Hat. Many projects have moved over to Apache DeltaSpike ,

What is in DeltaSpike? JPA Test-Control Module Role Core missing CDI @Stereotypes Bean Validation Container Control CDI container booting and shutdown and associated context lifecycle management Data Declarative queries, reducing boilerplate JPA @Transactional context and scope JSF Type-safe view config, multi-window handling, new scopes (WindowScoped, ViewScope, ViewAccessScoped, GroupedConversationScoped) and integration with DeltaSpike “core” messages and exception handling Scheduler   Security Servlet Test-Control CdiTestRunner

EntityManager without DeltaSpike (demo) EntityManager's life cycle depends on its type, which can be: Full blown Application server Container-managed transactional Container-managed extended Servlet and Standard Edition Application-managed With Application managed: Create Custom Weld Junit runner Boot a Transaction manager (Seam) or create a custom EntityManager scope: entityManager.getTransaction().begin() entityManager.getTransaction().commit(); entityManager.getTransaction().rollback(); Dispose of Entity manager

EntityManager with DeltaSpike (demo) Annotation DAO with @Transaction Paved the way for @Transactional in Java EE 7 Inject DeltaSpike Runner

What we encounter Testing with JDBC CDI 101 Testing with CDI Summary DeltaSpike Summary

Summary JDBC testing JPA testing Use DBUnit and Derby tools Inject entity manager Use DeltaSpike test Controls

Next month - DeltaSpike Data vs Spring Data Questions?