Recommended: Sing it, brah! 5 fabulous songs for developers
JW's Top 5
Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs
Page 5 of 5
@WebContextConfiguration(
webContextLocations = Array("/WEB-INF/sw-servlet.xml"),
contextLocations = Array("classpath*:/META-INF/spring/module-context.xml"))
@DataSource(name = "java:comp/env/jdbc/test",
driverClass = classOf[JDBCDriver], url = "jdbc:hsqldb:mem:test")
@TransactionManager(name = "java:comp/TransactionManager")
class IndexControllerTest extends Specification {
@Autowired var riderManager: RiderManager = _
"web roundtrip test" in {
val rider = new Rider()
rider.setUsername("aaaa")
rider.setFullName("Jan")
Json(put)("/riders.json", rider)
val savedRider = riderManager.getByUsername("aaaa")
val wo = Xhtml(get)("/riders/" + savedRider.getId + ".html")
Xhtml(post)((wo!) << ("#fullName", "Edited Jan"))
riderManager.getByUsername("aaaa").getFullName must_== ("Edited Jan")
}
}
The code in Listing 7 verifies that the system can accept an HTTP PUT to the /riders.html URL with some parameters. On receiving the PUT request, I verify that the system inserts the rider object specified in the parameters of the request. Once inserted, I verify
that the system can also execute the HTTP GET request to load the newly created rider.
The result of loading the rider is an XHTML document. In order to verify that the document contains the correct information,
I use a jQuery-style selector to modify the value of the input element with the id fullName. Once I have the XHTML document, I'll verify the HTTP POST of the XHTML form, which should result in an update to the rider object. Finally I'll check that the system has correctly
saved the edits to the Rider object.
If you're already a Spring developer and you've been curious about incorporating Scala's functional programming features into your applications, then you can start by implementing your test code in Scala. Doing so will help you learn the patterns of object-functional programming without committing beginner code to your main code base. Specs2 Spring is a solid testing framework and could be a good starting point for this approach to learning Scala.
Jan Machacek is the technical director of Cake Solutions. He is a highly experienced Java enterprise architect, consultant, and developer with strong technical and team management skills. Jan has led teams through the perils of agile software delivery, bringing control and value to businesses and the joy of programming to technical teams. Alongside several articles, Jan has authored four books, including Pro Spring and Pro Spring 2.5. He regularly speaks at conferences and developer events in the UK and abroad and is the editor of the Open Source Journal. Jan leads three open source projects: Specs2 Spring, Spock Spring Integration, and Scalad. In his spare time, Jan competes in time trials and road races as a member of the Manchester Wheelers' Cycling Club.
Read more about Tools & Methods in JavaWorld's Tools & Methods section.