Matt RaibleMatt Raible is a Java Champion and Developer Advocate at Okta. developer.okta.com

The JHipster Mini-Book The JHipster Mini-Book is a guide to getting started with hip technologies today: Angular, Bootstrap, and Spring Boot. All of these frameworks are wrapped up in an easy-to-use project called JHipster.

This book shows you how to build an app with JHipster, and guides you through the plethora of tools, techniques and options you can use. Furthermore, it explains the UI and API building blocks so you understand the underpinnings of your great application.

For book updates, follow @jhipster-book on Twitter.

10+ YEARS


Over 10 years ago, I wrote my first blog post. Since then, I've authored books, had kids, traveled the world, found Trish and blogged about it all.

AppFuse Changes: Unit Testing with Easy Mock and Spring's Struts Plugin

I have a couple of proposal for the next AppFuse release. Let me know what you think:

  • Change service and action/controller tests to use Easy Mock to mock dependencies. This will likely require a bit more code in the test, but it'll allow true unit testing of components. Current tests are more like integrations tests, which tend to be slower. The Canoo WebTests will continue to act as the integration tests that verify functionality top-to-bottom.
  • Change Struts to use Spring's Struts Plugin. XDoclet's Spring stuff should make this pretty easy so you don't have to modify any XML - just like the current situation. The advantage of this is you can use dependency injection on your actions, rather than getBean(...).

I hope to get these in, along with a WebWork option, in the 1.6 release. I'd love to get 1.6 done and released in August, but I'm probably dreaming since I'd like to finish Spring Live in the same time frame. Of course, I'm also planning on fixing any bugs that are currently entered.

Posted in Java at Aug 02 2004, 11:34:21 AM MDT 12 Comments
Comments:

Is there an example anywhere of using the Struts Plugin? I'm not sure if I understand why this would be any better alternative than just using getBean().

Posted by Dave Keller on August 02, 2004 at 01:02 PM MDT #

The advantage of using the Struts plugin is that your struts action are managed beans just like the rest of the beans in your application. No need for any spring imports or anything. Just put in a setter and the dependencies are there. It's really great. I would love to see how you can write tests for Struts actions that use the Struts plugin with mock objects. I have spent a little time working on it and haven't figured it out. StrutsTestCase wants to create the action instances for you, so you don't have a chance to inject the mock objects.

Posted by No one on August 02, 2004 at 01:24 PM MDT #

Using easyMock is definitely a good choice, especially it is taking to long to run the Canoo test. For Continuous Integration, time is of the essence. Run the easyMock test more regularly (say every 10min), Canoo WebTests will then only need to run at longer interval (say every 2 hrs). CruiseControl (http://cruisecontrol.sourceforge.net) will be able to help to automate these tasks at a regular interval.

Posted by Yong How on August 02, 2004 at 08:46 PM MDT #

I think for the 1.6 release you need a new logo. I know, how about a logo contest? You could even offer a prize for the winner (like an iPod or something). Previous contest winners are ineligible of course. You could have a new logo for every release! Or at least until I win. ;-)

Seriously speaking, Matt, I think the WebWork option should be highest on the list - you've been threatening to do it for a long time (you should read your own Roadmap more often...). I also think the Spring Struts plugin would be of higher value than Easy Mock for this release. I'd vote for doing Easy Mock in 1.6.1 as it's less of a "feature" and you have existing tests that work fine. It'd be better to focus on redoing all the tests all by themselves rather than mixed in with adding features, and also making 1.6.1 a really stable low-bug-count release. IMHO, of course.

Posted by gerryg on August 03, 2004 at 08:50 AM MDT #

Good suggestions Gerry - I was thinking of the same thing last night. WebWork/SiteMesh is the next thing I'm going to tackle.

Posted by Matt Raible on August 03, 2004 at 08:52 AM MDT #

When you use the Struts Plugin, does this eliminate the need for a struts-config file? Does Sping instanciate your Action classes instead of the Struts Servlet? Maybe I just had a rough weekend but I am having a hard time figuring out how this thing works. Is there a sample app somewhere that demonstrates using this plugin?

Posted by Dave Keller on August 03, 2004 at 03:31 PM MDT #

Dave - you'll still need a struts-config.xml file. In fact, it takes a little more work than normal as you'll have to define your action in struts-config.xml and again in action-servlet.xml (for Spring). You can download the MyUsers sample app from Spring Live - there's also a tutorial (PDF) that explains how this app was created. In addition, there's this documentation on the Struts Spring Plugin.

Posted by Matt Raible on August 03, 2004 at 03:43 PM MDT #

And the answer is "What is a Delegating Action Proxy?". That's what was getting me. You have to replace each of your action type class definitions in struts-config.xml with org.springframework.web.struts.DelegatingActionProxy. I was thinking you had to duplicate everything in both the struts-config and myapp-servlet.xml, which didn't make any sense. Thanks for the info.

Posted by Dave Keller on August 03, 2004 at 05:50 PM MDT #

jmock.org is worth checking if you aren't too far down the easymock road yet....

Posted by 24.27.58.11 on August 04, 2004 at 09:32 AM MDT #

In taking a quick look at jMock, it looks like it's a bit less code than Easy Mock, but provides the same functionality. Anyone know of a comparison article?

Posted by Matt Raible on August 04, 2004 at 10:37 AM MDT #

a good jMock article is coming ;) I personally think it is an excellent choice, and think it would be worth checking out as I find it a bit nicer to use than EasyMock.... just my preference! Dion

Posted by Dion Almaer on August 04, 2004 at 11:14 AM MDT #

Comparison here: http://www.jmock.org/easymock-comparison.html I know the Spring guys use EasyMock and I've used it a bit, but I hands-down prefer jmock, easier to think in for some reason. Allows you to mock classes as well as interfaces. Good guys writing it too, give it a go.

Posted by 24.27.58.11 on August 04, 2004 at 02:12 PM MDT #

Post a Comment:
Comments are closed for this entry.