Developing and testing enterprise Java applications

Slides:



Advertisements
Similar presentations
Introduction to NHibernate By Andrew Smith. The Basics Object Relation Mapper Maps POCOs to database tables Based on Java Hibernate. V stable Generates.
Advertisements

Introduction to the Spring Framework
11 Copyright © 2005, Oracle. All rights reserved. Creating the Business Tier: Enterprise JavaBeans.
Spring, Hibernate and Web Services 13 th September 2014.
.NET Database Technologies: Open-Source Frameworks.
Approaches to EJB Replication. Overview J2EE architecture –EJB, components, services Replication –Clustering, container, application Conclusions –Advantages.
G O B E Y O N D C O N V E N T I O N WORF: Developing DB2 UDB based Web Services on a Websphere Application Server Kris Van Thillo, ABIS Training & Consulting.
Next Generation Node (NGN) Technical Overview April 2007.
© 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
Application Architectures Vijayan Sugumaran Department of DIS Oakland University.
Introduction to EJB INFORMATICS ENGINEERING – UNIVERSITY OF BRAWIJAYA Eriq Muhammad Adams J
Copyright  2001 Urbancode Software Development, Inc. All Rights Reserved. Optimizing J2EE Applications A Comparison of J2EE Design Idioms and their Performance.
Session-01. Hibernate Framework ? Why we use Hibernate ?
Emmanuel Cecchet et al.  Performance Scalability of J2EE application servers.  Test effect of: ◦ Application Implementation Methods ◦ Container Design.
Intro to Spring CJUG - January What is Spring? “The Spring framework provides central transaction control of various objects.” This means that any.
An Introduction to Hibernate Matt Secoske
Data Persistence and Object-Relational Mapping Slides by James Brucker, used with his permission 1.
Distributed System Using Java 2 Enterprise Edition (J2EE)
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.
Chapter 10 EJB Concepts of EJB Three Components in Creating an EJB Starting/Stopping J2EE Server and Deployment Tool Installation and Configuration of.
EJB Overview Celsina Bignoli Distributed Business Applications Server DB Client DB Server DB.
Introduction to the Spring Framework By: Nigusse A. Duguma Kansas State university Department of Computer Science Nov 20, 2007.
NHibernate in Action Web Seminar at UMLChina By Pierre Henri Kuaté 2008/08/27
Entity Beans BMP Celsina Bignoli
Enterprise Java Beans Part I Kyungmin Cho 2001/04/10.
Enterprise JavaBeans. What is EJB? l An EJB is a specialized, non-visual JavaBean that runs on a server. l EJB technology supports application development.
© 2006 by BEA Systems Inc; made available under the EPL v1.0 | March 2006 | Java Annotation Processing (APT) in the Eclipse JDT Gary Horen BEA Systems.
Opus College - overview. OpusCollege - background First project: ICT Capacity Building Mozambican Higher Education Institutions Partners: RUG Groningen,
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.
© 2011 Pearson Education, Inc. Publishing as Prentice Hall 1 Chapter 14 Using Relational Databases to Provide Object Persistence (Overview) Modern Database.
Hibernate Persistence. What is Persistence Persist data to database or other storage.  In OO world, persistence means persist object to external storage.
JBoss at Work Databases and JBoss Chapter 4 Jeff Schmitt October 26, 2006.
Domain and Persistence Patterns. Fundamental Pattern Types Design Patterns Business Logic Patterns.
Java EE Patterns Dan Bugariu.  What is Java EE ?  What is a Pattern ?
Topic : Hibernate 1 Kaster Nurmukan. An ORM tool The problem fixed by ORM Advantage Hibernate Hibernate Basic –Hibernate sessionFactory –Hibernate Session.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 JSP Application Models.
1 Nov 29, 2005 Object Relational Mapping Frameworks Wiene Höweler.
1 Copyright © 2004, Oracle. All rights reserved. Oracle Application Development Framework.
Enterprise JavaBeans 3.0. What is EJB 3.0 -Reusable server-side component framework-technology -Designed to support building demanding enterprise – level.
1 Distributed System using J2EE. 2 What is J2EE?  J2EE (Java2 Enterprise Edition) offers a suite of software specification to design, develop, assemble.
Introduction to EJB. What is an EJB ?  An enterprise java bean is a server-side component that encapsulates the business logic of an application. By.
Java Programming: Advanced Topics 1 Enterprise JavaBeans Chapter 14.
Topic : Hibernate 1 Kaster Nurmukan. An ORM tool Used in data layer of applications Implements JPA.
Enterprise JavaBeans: Fundamentals. EJB Fundamentals(c)CDAC(Formerly NCST)2 Contents Introduction Technology Overview EJB Architecture EJB Specification.
EJB Enterprise Java Beans JAVA Enterprise Edition
Google Code Libraries Dima Ionut Daniel. Contents What is Google Code? LDAPBeans Object-ldap-mapping Ldap-ODM Bug4j jOOR Rapa jongo Conclusion Bibliography.
Leveraging ColdSpring to build a robust Flex applications Chris Scott, Cynergy Systems.
Best 3 Software Development Languages. Hibernate Training Hibernate is a high-performance object-relational mapping tool and query service. Hibernate.
J2EE Lecture 6: Spring – IoC and Dependency Injection
Introduction to Advanced Java Programming
Chris Menegay Sr. Consultant TECHSYS Business Solutions
Introduction to J2EE Architecture
Enterprise Application Architecture
Enterprise Java Bean. Overview of EJB View of EJB Conversation Roles in EJB, Types of Enterprise Beans Lifecycle of Beans Developing Applications using.
Design and Maintenance of Web Applications in J2EE
Intro to Spring CJUG - January 2013.
Inventory of Distributed Computing Concepts and Web services
ISE 390 Dynamic Web Development
Introduction to Enterprise JavaBean
Distributed System Using Java 2 Enterprise Edition (J2EE)
Building a Rich Domain Model
Data Model.
Testing a persistence layer
Knowledge Byte In this section, you will learn about:
Component-based Applications
Component Technology Bina Ramamurthy 2/25/2019 B.Ramamurthy.
Enterprise Java Beans.
Presentation transcript:

Developing and testing enterprise Java applications Chris Richardson cer@chrisrichardson.net http://www.chrisrichardson.net 4/7/2019 Copyright (c) 2005 Chris Richardson. All rights reserved.

Copyright (c) 2005 Chris Richardson. All rights reserved. Who am I? Twenty years of software development experience Building object-oriented software since 1986 Developing with Java since 1996 Author of POJOs in Action Run a consulting company that helps organizations develop software more effectively 4/7/2019 Copyright (c) 2005 Chris Richardson. All rights reserved.

Copyright (c) 2005 Chris Richardson. All rights reserved. Key points EJBs are (mostly) a bad idea Plain Old Java Objects and lightweight frameworks make development easier and faster Don’t access the DB if you want thorough tests that execute quickly 4/7/2019 Copyright (c) 2005 Chris Richardson. All rights reserved.

Copyright (c) 2005 Chris Richardson. All rights reserved. Agenda Overview of enterprise Java Developing with POJOs and lightweight frameworks Effective testing strategies 4/7/2019 Copyright (c) 2005 Chris Richardson. All rights reserved.

Copyright (c) 2005 Chris Richardson. All rights reserved. J2EE architecture Client Server From J2EE spec 4/7/2019 Copyright (c) 2005 Chris Richardson. All rights reserved.

Copyright (c) 2005 Chris Richardson. All rights reserved. EJB strengths It’s the standard for building object-oriented, distributed applications in Java Declarative transactions and security Truly distributed applications where EJBs participate in transactions initiated by a remote client Messaging-oriented applications that can benefit from message-driven beans 4/7/2019 Copyright (c) 2005 Chris Richardson. All rights reserved.

Copyright (c) 2005 Chris Richardson. All rights reserved. EJBs weaknesses But most applications don’t need distributed transactions initiated by a remote client Code is coupled to the server container Long edit-compile-debug cycles Slow development and testing Excessive complexity Complicated XML descriptor files Complicated IDE requirements EJB encourage procedural programming and make object-oriented programming difficult Broken object/relational mapping EJB 3 fixes some things but … 4/7/2019 Copyright (c) 2005 Chris Richardson. All rights reserved.

Copyright (c) 2005 Chris Richardson. All rights reserved. Agenda Overview of enterprise Java Developing with POJOs and lightweight frameworks Effective testing strategies 4/7/2019 Copyright (c) 2005 Chris Richardson. All rights reserved.

The solution: POJOs = Plain Old Java Objects Java objects that don't implement any special interfaces Coined by Fowler to make it sound just as exciting as JavaBeans, Enterprise JavaBeans 4/7/2019 Copyright (c) 2005 Chris Richardson. All rights reserved.

Simple idea with surprising benefits Simpler development Test without an application server Business logic and persistence are separate Faster development Test without deploying Easier testing More maintainable Modular object-oriented code Loosely coupled design Decouple technologies from core business logic 4/7/2019 Copyright (c) 2005 Chris Richardson. All rights reserved.

Copyright (c) 2005 Chris Richardson. All rights reserved. Persisting POJOs  Object/relational mapping framework Hibernate Very popular open-source project JDO Standard from Sun – JSR 12 and JSR 243 Multiple implementations: Kodo JDO, Versant, JPOX EJB 3/JSR 220 persistence Intended to be “the” standard Java persistence mechanism But it has limitations, … 4/7/2019 Copyright (c) 2005 Chris Richardson. All rights reserved.

ORM framework features Declarative mapping CRUD API Query language Transaction management Lazy and eager loading Caching Detached objects 4/7/2019 Copyright (c) 2005 Chris Richardson. All rights reserved.

Making POJOs transactional An easy to use solution is the Spring framework Popular open-source framework for simplifying J2EE development Lightweight container for POJOs Provides declarative transactions for POJOs Makes it easier to use JDO and Hibernate 4/7/2019 Copyright (c) 2005 Chris Richardson. All rights reserved.

Spring lightweight container Lightweight container = sophisticated factory for creating objects Spring bean = object created and managed by Spring You write XML that specifies how to create and initialize the objects Lightweight container can wrap an object with a proxy Proxy masquerades as the original object Proxy executes arbitrary code before and after method call Spring uses proxies for: transaction management Security … 4/7/2019 Copyright (c) 2005 Chris Richardson. All rights reserved.

Copyright (c) 2005 Chris Richardson. All rights reserved. Agenda Overview of enterprise Java Developing with POJOs and lightweight frameworks Effective testing strategies 4/7/2019 Copyright (c) 2005 Chris Richardson. All rights reserved.

POJO application design POJO facade Domain model Database access 4/7/2019 Copyright (c) 2005 Chris Richardson. All rights reserved.

Copyright (c) 2005 Chris Richardson. All rights reserved. Testing overview Challenge You need lots of tests (at every level) You want the tests to run quickly Databases are slow Solution Test without the database where possible Use an in-memory database such as HSQLDB Without a database (fast) Test the business logic and repositories with mock objects Test the object/relational mapping With a database (slow) CRUD tests for persistent objects Test the queries With a database (fast) Test the database schema 4/7/2019 Copyright (c) 2005 Chris Richardson. All rights reserved.

Testing the domain model Goal: Test the business logic Top-down, test-driven development Service => Domain entity,… How: Use fast, easy to write, in-memory tests Use mocks for an object’s collaborators Especially the repositories, which access the DB 4/7/2019 Copyright (c) 2005 Chris Richardson. All rights reserved.

Mock object tests for the repositories Repository = domain model class that wraps the ORMF Problem: Bugs in the logic of the repositories Testing against the DB is slow Solution Use mock objects for the ORMF APIs 4/7/2019 Copyright (c) 2005 Chris Richardson. All rights reserved.

Test the object/relational mapping Problem: Incorrectly defined mapping, e.g. forgetting to map a field is a common bug But tests that save objects and check the contents of the DB are slow to execute and tedious to write Solution: Read XML or metadata Make assertions about the mapping 4/7/2019 Copyright (c) 2005 Chris Richardson. All rights reserved.

Copyright (c) 2005 Chris Richardson. All rights reserved. Testing the schema Problem: Object/relational mapping can reference non-existent tables and columns Only some execution paths will access those tables and columns Solution Write a test that verifies that all referenced tables and columns exists How Persistence framework-specific 4/7/2019 Copyright (c) 2005 Chris Richardson. All rights reserved.

CRUD tests for the persistent objects Problem: Database constraints can prevent application from updating the database Solution Verify that the objects can be created, updated and deleted Each test takes an object through its lifecycle Creates and saves an object One or more times: Load and update it Delete the object These tests are slow 4/7/2019 Copyright (c) 2005 Chris Richardson. All rights reserved.

Copyright (c) 2005 Chris Richardson. All rights reserved. Testing queries Problem: Malformed queries Logic errors in queries, e.g. < instead of <= Solution: Write tests for the queries Each test: Populates database with test objects Execute queries with parameters Verify that the query returns the expected result These tests can be slow 4/7/2019 Copyright (c) 2005 Chris Richardson. All rights reserved.

Copyright (c) 2005 Chris Richardson. All rights reserved. Testing the façade Façade = encapsulates the business logic Mock object tests Mock the domain objects called by the facade Integration tests: Façade is a good place to test the business tier independently of the UI Write tests for the façade that access the database 4/7/2019 Copyright (c) 2005 Chris Richardson. All rights reserved.

Copyright (c) 2005 Chris Richardson. All rights reserved. Summary Use POJOs and lightweight frameworks instead of EJB Test at every level Test without the database as much as possible 4/7/2019 Copyright (c) 2005 Chris Richardson. All rights reserved.

Copyright (c) 2005 Chris Richardson. All rights reserved. For more information Email: cer@chrisrichardson.net Blog: http://chris-richardson.blog-city.com My book (4Q05): POJOs in Action 4/7/2019 Copyright (c) 2005 Chris Richardson. All rights reserved.