Title: Test Driven Development
1Test Driven Development
- TDD with Maven, Spring Framework, CXF and JUnit
2Summary
- This presentation will cover a single Maven web
module, using the Spring framework to create a
CXF based webservice, and testing a remote client
with JUnit to verify the CXF contract.
3This presentation will cover the following topics
- Maven 2
- CXF
- Spring Framework
- Spring Remoting
4Takeaway
- Attendees will take away a new insight as to how
to create setup a Maven web module, how to add
Spring, Cargo and CXF capabilities and how to use
these technologies to perform unit testing with a
test driven development lifecycle.
5About the Author
6About Mick Knutson
- President of BASE Logic, Inc (http//www.baselogic
.com) - Blog (http//www.baselogic.com/blog)
- Won Best in Show for GoGrid.com _at_ Linux World
2008 - Manage Multiple Enterprise Deployments _at_ FedEx
with gt4MIL message transactions per hour.
7Setting Up Maven
- Setting up a single module Maven project.
8Maven Quick Start
- Download Apache Maven (http//maven.apache.org)
- Unpack Maven to C/maven
- Install Sun JDK to c/jdks/java (NOT C/Program
Files/java) - Create workspace for new project
(c/code/ucc2009) - Create blank Webapp archetype (template)
- mvn archetypecreate -DgroupIdcom.mycompany.app
-DartifactIdmy-webapp -DarchetypeArtifactIdmaven
-archetype-webapp - Open CMD prompt to c/code/ucc2009
9Convention Over Configuration
- Java source Directory
- ./src/main/java/
- Resources Directory
- ./src/main/resources/
- Webapp Directory
- ./src/main/webapp/
- Testing Source
- ./src/test/java/
- Testing Resources
- ./src/test/resources/
10Maven Quick start
- Single Maven Module directory layout
11Project Object Model (pom.xml)
- Project Build Descriptor
- Group Id
- Artifact Id
- Artifact Type (jar, war, ear, pom)
- Version
- Dependency Management
- Plugin Management
- Build Properties
12Adding Spring dependencies
- In your pom.xml,
- add the following
- Spring dependencies
- Note ltpropertygt
- ltspring.versiongt2.5.6lt/spring.versiongt
13Spring Framework
- Spring does many things, but when you strip it
down to its base parts, Spring is a lightweight
dependency injection and aspect-oriented
container and framework.
14Adding Spring Context
- ./src/main/webapp/WEB-INF/applicationContext.xml
15Adding Spring Context
- ./src/main/webapp/WEB-INF/applicationContext-servi
ces.xml
16Adding CXF dependencies
- In your pom.xml,
- add the following
- CXF dependencies
- Note ltpropertygt
- ltcxf.versiongt2.2.3lt/cxf.versiongt
17Adding CXF Context Server entries
- Create applicationContext-services.xml
18Adding web.xml entries
- Adding Spring and CXF entries
19Adding JUnit Test Case
- Create new Test Case
- Instantiate Test Spring Context
- Get Client Proxy Bean
- Execute Proxy Methods on Bean
- Assert outcome.
20Adding JUnit Test
- Create ./src/test/java//MessageWebServiceTest
21Create Service for Test Case
- Create Service to match our test
22Create Service for Test Case
- Create Service Interface
- Annotate the Interface as _at_WebService
- Create Service Implementation Class
- Annotate the Class as _at_WebService defining the
Service Interface as the endpointInterface.
23Adding Service Interface
- Create src/main/java//MessageService
24Adding Service Implementation
- Create src/main/java//MessageServiceImpl
25Adding Spring Test Context
- Create applicationContext-test.xml
26Adding test.properties
- Create src/test/resources/test.properties
27Cargo Tomcat Plugin for Maven
- Compile and Package War
- Start embedded Tomcat container before running
Tests - Deploy war to Tomcat container
- Run Test Cases
- Assert Test Outcome
- Stop embedded Tomcat container after tests
complete.
28Cargo Tomcat Plugin
- We want to start Tomcat with the Cargo plugin and
deploy our webapp before running unit tests
29Running Standalone Cargo Plugin
- By running run-cargo-tomcat.bat, we can deploy
our war, and verify our service endpoint in a
browser manually
30CXF Generated WSDL
31Tying it all together
- Compile and Package war
- Start Cargo Tomcat
- Deploy war to Tomcat
- Run Tests
- Assert Results
- Stop Cargo Tomcat
32Start Cargo, and Run Test
- Executing mvn clean verify
33Test Success
34Next Steps
- Debug-As JUnit Tests in Eclipse
- Remote Debugging with Eclipse
- Use Easy Mock to stub Spring services
- Integrate Coburtura to measure Test Code Coverage
35Questions?
- Any questions of comments?
36The End
- Thank you for your time and attention
37Mick Knutson
- BASE Logic, Inc.Enterprise Architecture,
Design, Mentoring Agile ConsultingPhone.
(866) BLiNC-411 (254-6241-1)Fax. (415)
685-4233Website http//www.baselogic.comWebsit
e http//www.baselogic.com/blogLinked IN
http//www.linkedin.com/in/mickknutson
38References
- Source Code (http//baselogic.com/code/ucc2009/web
app.zip) - Slide Deck PPT (http//baselogic.com/code/ucc2009/
ucc.ppt) - Apache Maven (http//maven.apache.org)
- Springframework (http//www.springsource.com)
- CXF (http//cxf.apache.org)
- Cargo Plugin (http//cargo.codehaus.org/Maven2plu
gin) - SOAP UI (http//soapui.org)