Download presentation
Presentation is loading. Please wait.
1
Test Driven Development
TDD with Maven, Spring Framework, CXF and JUnit When times get tough, the tough get going…
2
Summary 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.
3
This presentation will cover the following topics
Maven 2 CXF Spring Framework Spring Remoting Cargo Tomcat JUnit Some of the tools you will need to create your world-wide presence.
4
Takeaway 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.
5
About the Author Mick Knutson This should begin the presentation.
6
About Mick Knutson President of BASE Logic, Inc ( Blog ( Won ‘Best in Show’ for Linux World 2008 Manage Multiple Enterprise FedEx with >4MIL message transactions per hour.
7
Setting up a single module Maven project.
Setting Up Maven Setting up a single module Maven project. This should begin the presentation.
8
Maven 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 archetype:create -DgroupId=com.mycompany.app -DartifactId=my-webapp -DarchetypeArtifactId=maven-archetype-webapp Open CMD prompt to c:/code/ucc2009
9
Convention 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/**
10
Maven Quick start Single Maven Module directory layout
11
Project Object Model (pom.xml)
Project Build Descriptor Group Id Artifact Id Artifact Type (jar, war, ear, pom) Version Dependency Management Plugin Management Build Properties
12
Adding Spring dependencies
In your pom.xml, add the following Spring dependencies Note <property>: <spring.version>2.5.6</spring.version>
13
Spring 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.
14
Adding Spring Context ./src/main/webapp/WEB-INF/applicationContext.xml
15
Adding Spring Context ./src/main/webapp/WEB-INF/applicationContext-services.xml
16
Adding CXF dependencies
In your pom.xml, add the following CXF dependencies Note <property>: <cxf.version>2.2.3</cxf.version>
17
Adding CXF Context Server entries
Create applicationContext-services.xml
18
Adding web.xml entries Adding Spring and CXF entries
19
Adding JUnit Test Case Create new Test Case
Instantiate Test Spring Context Get Client Proxy Bean Execute Proxy Methods on Bean Assert outcome.
20
Adding JUnit Test Create ./src/test/java/**/MessageWebServiceTest
Talk about the Unit test, and how Spring starts the IoC container.
21
Create Service for Test Case
Create Service to match our test
22
Create Service for Test Case
Create Service Interface Annotate the Interface Create Service Implementation Class Annotate the Class defining the Service Interface as the endpointInterface.
23
Adding Service Interface
Create src/main/java/**/MessageService Talk about the Unit test, and how Spring starts the IoC container.
24
Adding Service Implementation
Create src/main/java/**/MessageServiceImpl Talk about the Unit test, and how Spring starts the IoC container.
25
Adding Spring Test Context
Create applicationContext-test.xml
26
Adding test.properties
Create src/test/resources/test.properties
27
Cargo 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.
28
Cargo Tomcat Plugin We want to start Tomcat with the Cargo plugin and deploy our webapp before running unit tests
29
Running Standalone Cargo Plugin
By running run-cargo-tomcat.bat, we can deploy our war, and verify our service endpoint in a browser manually Run-cargo-tomcat.bat executes: mvn -Dcargo.wait=true cargo:start -e
30
CXF Generated WSDL
31
Tying it all together Compile and Package war Start Cargo Tomcat
Deploy war to Tomcat Run Tests Assert Results Stop Cargo Tomcat
32
Start Cargo, and Run Test
Executing mvn clean verify
33
Test Success Successful Test result
34
Next 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
35
Any questions of comments?
This is the end of the presentation…
36
Thank you for your time and attention…
The End… Thank you for your time and attention… This is the end of the presentation…
37
Mick Knutson BASE Logic, Inc. Enterprise Architecture, Design, Mentoring & Agile Consulting Phone. (866) BLiNC-411: ( ) Fax. (415) Website: Website: Linked IN:
38
References Source Code (http://baselogic.com/code/ucc2009/webapp.zip)
Slide Deck PPT ( Apache Maven ( Springframework ( CXF ( Cargo Plugin ( SOAP UI (
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.