JSF Central - Daniel Hinojosa talks about Pitfalls and Testing with JBoss Seam
JSF Central

 
 Home 
 
 Products 
 
 Articles & Books 
 
 Resources 
Community Chat
 
Daniel Hinojosa talks about Pitfalls and Testing with JBoss Seam
by Kito Mann
28 Jan 2010 02:00 EDT

In this podcast, JSFCentral editor-in-chief Kito D. Mann talks with Daniel Hinojosa about testing JBoss Seam applications from the bottom up, and Seam pitfalls. This interview was recorded in September of 2008 at the JSF Summit, formerly called JSFOne, in Vienna, Virginia.


Podcast (MP3)
Welcome to the JSFCentral podcast # 19 for the week of January 18th, 2010. This series of podcasts features interviews, news, and commentary for those working with JavaServer Faces technology.
Kito Hello, my name is Kito Mann. I am here at JSFOne 2008. This is day two of the conference. We are in Vienna, Virginia. I am here with Daniel Hinojosa. Daniel is one of our speakers at JSFOne, covering Seam related topics. Why don’t you start by telling us what you do, what your story is?
Daniel I have been a self-employed developer, instructor, and consultant since early 2000. I have been doing that and been very happy with my eight-foot commute to the office. I teach -- over at the University of New Mexico continuing education -- programming in Java or object oriented programming and other object oriented programming languages, Ajax and things like that. I am trying to infect people with the Seam virus, to get people to use Seam. I think it is probably the best web framework out there, so I am joining up on JSFOne and spreading the good word on JBoss Seam.
Kito Okay. You mentioned the other day that you were a framework “junkie.”
Daniel Yesterday I said “fan boy,” and I was like “I think I am insulting myself by saying that, so I will just call myself an Uber user and wish I had never said that previously.” I am an Uber user of the Seam framework. I think I have tried just about every web framework out there with the exclusion of Wicket, so I don’t want to lump them into frameworks I have decided to pass on, but I tried a lot of them and they didn’t have what I needed. A lot of this was at the beginning of a project, and a lot of people try different frameworks at the beginning of a project. That happened to me as well. I wanted more out of regular JSF and I tried Stripes…everyone took a look at Struts, everyone knew Struts but there was something that was still not comforting about it. I used my own “craptaculous” framework for a long time and finally Seam came along. It had stateful, it had PDFs, it had charting, it had conversations and I am like “wow, this is what I am going to stick with.”
Kito Anything else you want to add in terms of your bio?
Daniel I am on the JSF expert group as well -- because of all my other Spring projects, not as active as I would like to be. I have just been doing this awhile, trying to improve Java web development. That is essentially the sole function of my job.
Kito And talking at conferences. Daniel did a great session on Spring 3.0 today. You can always find him at random conferences. So how did you get involved with SpringSource?
Daniel Basically I had been doing a lot of Web Flow with my previous company with JSF, with Web Flow 1.0 actually. I found that Web Flow greatly improved what we were trying to do with some pretty complex JSF applications and this was back in JSF 1.1 days. The whole problem there with not having a finer grain scope than session scope -- that whole canonical JSF problem -- we found that Web Flow fit really well in there, but the JSF integration in Web Flow at first was not 100% perfect. We had to do a good bit of extension of it. That is how I really got involved with the project. I started feeding back a number of contributions to keep Donald -- who is the lead of the project -- feeding things back through the forms and JIRA and everything. So that is how Keith and I got to know each other and around the time that they started expanding the R and D department, he called me up and said "hey do you want to come work for us?" And the original intention was to focus on Web Flow 2, which he was just about to start working on, and really re-think the way Web Flow integrates with JSF.
Kito Okay. So you are doing a couple of different topics here at the conference, right?
Daniel Yep.
Kito You are doing Seam hazards….
Daniel Traps and Hazards. I think I named it wrong, but on my slides I have the Atari Pitfall game.
Kito I was just thinking about that.
Daniel It should have been Seam Pitfalls. I told the people at the conference that Seam can be your best friend right away, or can be kind of like your enemy at first. Seam has Seam-gen which is kind of like AppFuse, or like Grails, where you can get started with an app right away. It generates a build XML for you. Knowing a lot of developers, they get the build XML, take a look at it and say “I don’t like that. I am going to go ahead and change it. I want my own build XML.” That is pitfall number 1 in my presentation. They don’t want to use the build, but…unfortunately there is a testing mechanism that is kind of fragile, but it is really good for integration testing. Unfortunately you get a lot of class path exceptions if you try to deviate from the build XML. Things like that, things that I learned, things that I got burnt heavily on and using Seam, reading the documentation. I had my own ego and was like “no, no I need to do it my way.” I got burned doing that so this is just a forewarning of my failures onto others so that they don’t make the same mistakes. That is what that presentation is about.
Kito With Seam-gen and the Seam-gen build issue, do you think that people should use…are better off starting a project with Seam-gen, or do you think they are better off, if they have particular constraints, to start a project from scratch using Seam?
Daniel Definitely Seam-gen.
Kito Okay.
Daniel Treat it like you are swimming for the first time. You are going to have to hold onto that wall, and it depends on how quickly you learn or how quickly you research the build. Or better yet, Subversion is a very good tool. Start off on Seam-gen for a bit, then maybe branch out onto an experimental branch on your version control. Then try your own build and see how it works from there. Definitely keep that Seam-gen around with your project because it offers a lot of utilities built in. One of them happens to be debugging. You have the Facelets debugging already turned on for you for a development profile. You have that and you also have the JBoss debugging, so you have all these tools ready to go using Seam-gen. A lot of people just deviate from it, and they end up posting on seamframework.org -- which is a very good site with a good forum -- but a lot of the questions are “Seam doesn’t work, I got this error and it says ‘strange class path error.’ What’s wrong with you guys? “There is nothing wrong with it, it’s just that certain jars need to be loaded in a certain order so it is probably best that you use Seam-gen.
Kito Okay. So I imagine there are probably at least two different approaches to using Seam-gen. One would be where you use Seam-gen once, create the scaffolding for the application, and then work normally off the top of it. Another option would be to use Seam-gen, then make some changes, regenerate, make some changes, regenerate, etc. Have you tried both methods before?
Daniel I have tried both and I ended up just – because it provides three basic folders for you: model, action, and test -- and I just use my id to create the classes out of there. Seam-gen offers your “create entity,” “create action,” and different kinds of things very much like Rails or Grails has. I have used those at first but then I ended up creating a new class, because from there I kind of know what I want. You can take different approaches with that. The value of that whole Seam-gen, I think, is in that whole build XML file.
Kito I see.
Daniel And it’s not lengthy. It’s not unreadable in any way, but the class loading and the order they do that is probably the most valuable to it.
Kito Okay. So you said that one of the issues that you have seen people run into is they try to deviate too much from the way Seam expects things to work when they start writing applications?
Daniel Yeah, they see the build and they see the build XML and they say “I don’t want to use it.” And they go over to do their thing without an understanding about some of the Seam features. There is nothing wrong with using your own build after a while, but take some time to understand the build XML that is provided for you. Learn from there, and then go off and do whatever you need to do.
Kito What about in terms of the programming model? Like what are the three biggest things that you see when you start writing in the Seam application that you are like “oh, I didn’t think it worked that way,” or you try to do something and you think “maybe I shouldn’t have changed that.”
Daniel No. I think you could go and experiment and do whatever you like there but I think as a new user, if you have come from a non-component based web framework, you are not handling the request response as you used to before. You are just mapping a component. You can inject things from other components from the request parameters. If you are coming from a Struts background, you may want to take some time to understand how component based frameworks do with that one. Conversations in Seam are a new idea – probably an old idea but new to everyone. Conversations use a little marker to pass from page to page and it wraps a unit of work. A wizard would be a good example. You would have four pages that do a certain amount of work: ask a name, get some account information, store it in the database, and that’s your amount of work. That lies within the session; it is not particularly the session. I did some apps myself where I found out I was abusing session, because coming from a classical framework – say a shopping cart – you are like “I am going to put that cart in the session.” After learning more about conversations -- and I think a lot of Seam or the new Spring web flow developers will understand -- maybe that could strategically be a good idea to place in a conversation. Just some things that you will find some differences in moving to a framework like that.
Kito Okay. So if you compare Seam to some of the other frameworks you have worked with – you mentioned Stripes and Grails – what were the things that drew you to Seam over and above those other frameworks?
Daniel I do like Grails a lot, in fact I teach an Ajax class on Grails and my Ajax students come from various backgrounds like Ruby on Rails or .Net, and it is really tough to teach an Ajax class with it, so I ended up using Grails. I think Grails is remarkably fast to set up and to create an app. I guess in that scenario, if I needed to create an app in a few days I would probably just do Grails. It is really lightweight, easy to bring up and set up. But for me -- if I wanted to choose something a little bit more long lasting, or things that have to be maintained and I have better control over each of the components of that -- then I would definitely move to Seam. Mostly the deliverables. This is purely opinion. There is no fact to that, but I do like Grails a lot.
Kito What is it about Seam, though? You said it has more moving parts, more things you need to work with, but is that really just it?
Daniel I think it was the integration testing that you get with it. When it started it had the PDF, it had the charting involved with it, and I think the way the components were mapped out. I have always been a fan of stateful enterprise beans and I like the idea of stateful, and so they were the first to come up with a web framework with a stateful idea. I mean JSF has always had the session that can keep the state there, but this one has integrating of that without having to create managed bean adapter classes. That was one of the things about JSF that – it was fine, but I didn’t want to create a managed bean just because the EL…in order to have the EL work with, it you had to have it in a certain format. You couldn’t have any parameters in the method at the time. I found that kind of limiting. What Seam does is, you don’t have to create a managed bean to interact with your session bean which interacts with your entity bean. It gets rid of that managed bean layer so that the app just interacts straight with that particular session bean or action.
Kito Right. You mentioned the whole stateful session bean component from Java EE. Have you done a lot of Java EE projects or did you end up doing more of them once you started working in Seam?
Daniel Actually, that “craptaculous” framework I was talking about? It was my attempt to do what Seam was. When I saw it, I was like “that’s it, that’s it!” I just didn’t have the time or the brains – because those are some powerful brains behind Seam. I needed the JSF and I needed stateful and I needed to get rid of managed bean and I needed an extended EL. So I guess if you boil it down to that, that’s what made me jump for joy, was Seam.
Kito That’s a perfect match.
Daniel Yes.
Kito Just so you know, we are trying to extend a lot of the EL stuff in JSF 2.
Daniel That was a question that some of us Seam heads wanted to know about JSF 2, on whether we can call methods with parameters, kind of an extended EL type of thing.
Kito What we have talked about is basically that feature. The JBoss EL also has projections and I think one or two other things. We are not as sure about those, but calling a method and sending parameters is something I think everybody wants. What is a little tricky though is that -- JCP is a fun place -- the EL spec is like a separate document that was originally developed with JSP 2.1, but it was broken out into a separate document with the idea that it could live by itself. There is no one working on JSP at all right now, so there is really no plan to make a next version of the EL spec right now. We will probably have to do it in JSF 2, which is kind of like not really where it is supposed to be, but I think we are definitely going to that. Pete Muir from JBoss has really been good about making clear basically how it works, and what is different about the JBoss EL and that kind of stuff.
Daniel He is an evil taskmaster so … I am just kidding, Pete, if you are listening.
Kito Alright so the other session that you are doing here is called Testing JBoss Seam Applications from the Bottom Up. What does that mean exactly?
Daniel Bottom up, I considered unit testing the bottom feeder type of test. The presentation starts off with unit testing, not really anything Seam specific but just using mocks. A unit test is just a test on your method without having to interact with other components or databases or other layers.
Kito You are saying a unit test in and of itself is a test of the method?
Daniel Yeah, you test the method and its isolation apart from anything else -- quick tests that you can do all the time, quickly. I talk about how to unit test particularly in Seam and how to mock out what Seam does so you can effectively unit test. Then we go to the next layer so we are heading up on this one, and we do integration testing. Now JBoss Seam has a number of great utilities. What Seam has is, when you are doing integration testing you have lifecycles that would start up an embedded JBoss server. You can run the test on this tiny little embedded JBoss server. So it is a tiny embedded Seam framework. Then you can call up components by their context name, invoke methods on it, and set certain variables just to see what the behavior is. When you are done with your integration testing, you shut down that server and report your successes and your failures on that, which I think is really neat. I don’t know what other web frameworks have that, but to me that was just something…and this was when I started getting test infected. So having that type of thing as part of your integration suite was over the top. It is a wonderful suite. I showed users how to do that with the integration testing, and then I did Selenium. Selenium is an acceptance testing framework from the browser end. A lot of you know Selenium already, but this is how to do Selenium with JBoss Seam or really JSF. As you know, whenever you make an ID, if you don’t provide an ID, one will be created for you. A lot of these elements, if you don’t name any IDs on any of them, you are going to have these strange J10, so always put IDs in there. The rest of it is Selenium, so nothing is too far apart from people who use Selenium on Rails or whatever. The only thing is to make sure you put the IDs; you end up with better testing atmosphere on that one. I do all those. I run Cobratura so they get to see the percentage of how well they are testing their code. Then I show them Hudson and bring all that in. All within 90 minutes.
Kito That is a lot of stuff in 90 minutes.
Daniel On that one, I am rambling.
Kito A couple of questions here. For the Seam integration tests, how do you mimic a request? Or do you work more at the level of grabbing a component and calling methods?
Daniel That’s right, it’s on the level of the components. So let’s say you have a request parameter that you are expecting in a component. In that framework it is just a set value. You are just mimicking what is coming in from the outside. You can’t really test that until the acceptance level, to see how it reacts to an actual true request parameter.
Kito Okay.
Daniel But from the bottom up, we have to still do some mimicking all the way up until we get to the acceptance testing. At that point we get to see it fully interact with the browser.
Kito One of the things I was wondering about the Seam integration tests – you are talking about loading this whole embedded container and running all these tests, actually using the real Seam container. Is that a slow process? It sounds like it may take a while.
Daniel That is actually pretty fast. You don’t want to do it every minute, at the end of every committal. As time goes on and your applications grow, it is going to take quite a while, the more tests you have on there. It is going to take a good amount of time, but starting up and shutting down that server is relatively fast. What it does is bring up an in memory database – Hypersonic – and it does everything that you need there. You can use DBUnit to bring in some fake data and to test how it is going there. What it does is it drops the database and recreates it with the fake data so that you always have a consistent test set every time you run it. The loading up and shutting down is not too bad, but I am sure as time goes by and your app becomes more developed over time, of course you are going to have more tests and that is going to take a while.
Kito So in terms of the testing frameworks that you are using in your presentation, were you using TestNG or JUnit for that?
Daniel In Seam, it comes prepackaged with TestNG. This was like a perfect harmony coincidence for me because I got started with testing when 3.5.1 came out.
Kito With JUnit, right?
Daniel Right. I didn’t really know what it was for, but after going to a few No Fluff Just Stuff conferences I was like “oh, okay I get it. You shouldn’t be developing software without tests.” So I was working with 3.5.1 and then JUnit 4 came out, and I believe when it came out Ant was tightly coupled with JUnit 4, and at the time Ant had to do an upgrade before you used JUnit 4 and there was a little controversy there.
Kito So you are saying it was tightly coupled with JUnit 3.5?
Daniel Yeah, and then when 4 came out, Ant had to be upgraded. Cedric Beust, the inventor of TestNG said “I just came out with this new testing framework” and it caught my attention right away. I think one of the big reasons is you can categorize your tests into groups. You can categorize them into unit testing, integration testing, acceptance testing, fast, slow, employee – like if you are having an employee-centric thing – or whatever type of focus you want to give. So if you are doing an employee module you can say “give me everything that has to do with an employee. Give me all the tests and make sure that they run through.” So with these categories you can just invoke them by some regular expression and you can have any category of test shape, or however you like. That won my heart over. So Seam uses TestNG. That was like a perfect fit for me. In this presentation that I have, the problem with testing under Seam is that they only have a generic @Test annotation that you can use. In the presentation I show them how to break that apart in Seam so that you can do a unit test, something fast so that when you go into your CruiseControl or your Hudson, your continuous integration server, the unit tests you would do at committal time -- to your Subversion – every minute, they are really quick. You can do the integration test every hour or at the end of the day or whatever schedule is right for your team. That is why I found it important to break that out. That was a little setback from Seam that they only supported the general all test type of thing. On this presentation I show them how to break that up and to use that. I am definitely a TestNG fan and it was just wonderful that Seam decided to include that in.
Kito So Seam has integrated support for TestNG. Obviously the unit test that you did at the first level was TestNG. Selenium has TestNG integration as well?
Daniel The neat thing about Selenium is right off the bat you can download your test in an HTML format. I think it is called a Fit format, to where you have three columns in HTML: the action you are trying to do, the URL that you are trying to do, and extra attributes. So they have that in the HTML format. You can use that in Selenium right away but there is a Selenium IDE – it is a Firefox plugin – and it is like a macro recorder. So you press “record” and it is recording every movement that you have on your website. For those that know Selenium, you are probably rolling your eyes -- “yes we know what Selenium is.” So you record all that and it records all your movements, then it generates your test case in an HTML format. You can go there and you can say “export that into Java, Ruby, C#...” I forgot the others but it has a whole wide range there. So now what I do in Seam is I export that to Java in a Java test in Java source code, and I take that and I put that into my test cases in Seam.
Kito Okay.
Daniel From that point there is another download called Selenium RC, and it is a server instance. You boot that up, it’s a small Jetty engine, and the really neat thing then, is from your Seam app you can say to do an acceptance test and the remote control would bring up Firefox or IE and it would automatically do all the entering, all the clicks that you needed to do. It is just a robot that’s ready and available to test your application.
Kito OK. We have gone from pure unit test to integration testing. We talked about Selenium for acceptance testing. What about the coverage tool, Cobratura? Tell us about that.
Daniel Cobratura – what that does is it is a report and it gives you data about how much of your code has been covered. Cobratura is Portuguese and Spanish for coverage. There is also Emma, another popular open source product, a very good product. Also Clover is by Atlassian. What it does is go through your code and says “this line we actually ran through.” “This line the test has been gone through.” It also offers a number on the side. It will say next to the method, “this method has been run 33 times in your tests.” People shouldn’t place too much confidence in it. You should have more confidence in the quality of your tests. This one just says “this has been covered.” “This has been run through by your testing.” Now if it hasn’t been tested – like if there is a method or line that hasn’t been invoked, then it will be highlighted in red and it will give you a percentage. Cobratura offers branch and line coverage. I think Emma – even though I am not too familiar with it – I think it offers three additional items. The people that do like Emma love it for that. I may be undereducated as far as how far Emma has come, but at the time I like Cobratura because I like Groovy a lot. I do a lot of testing with Groovy and you can use Cobratura with Groovy or Java. That is what led me to that one. Emma at this time I think is still Java only, but I have not gone back to research, so to the Emma people, I am sorry if I am mistaken there.
Kito The topmost layer would be Hudson, right? Which is continuous integration. Hudson is a Sun open source product. How do you think Hudson compares to Bamboo?
Daniel I have never used Bamboo. I have never used Continuum. I did use CruiseControl -- that is the extent of my life with continuous integration servers. I love Hudson because it is packaged as a war file, and you throw it into whatever container you want, and you manage your builds using a web UI. If you have used CruiseControl, you know that one is pure XML. Sometimes things don’t go right, right off the bat, just by editing in XML. This one is very nice to use and very pleasing to the eye. You can get set up with a job immediately. The other thing is it offers reports, so you can log in and see your coverage report online, you can view your test results. They have other plugins and what it does – for those who don’t know what continuous integration is, the continuous integration server listens to your version control, CVS or SVN. Whenever there is a new update it takes that, tests your code, and provides a report. Another thing that I do for my customers for web apps is that I also deploy it to a test server, so that every time during development they are able to take a look at how the website is or what it is doing. They are able to see all the bugs or all the wonderful things during development. They are always up to date. That way they never have to call me and say “how is the project going?” That is what the continuous integration does. I favor Hudson a lot just because of the large amount of plugins. I only scratched the surface as far as the amount of plugins that are available, but definitely check it out. I think it is hudson.dev.java.net.
Kito That sounds about right.
Daniel It is an excellent product to use.
Kito I think that is about all the questions I have. Anything else you would like to add?
Daniel No, except give Seam a try, and there are a lot of helpful people at seamframework.org. Stop by and ask questions. seamframework.org is all built on Seam so you can look to see how a Seam app looks like in the real world. I will be posting my slides on the JSFOne site and my demo app on testing will be there. I will also post it on seamframework.org. I will probably post it at my website, evolutionnext.com/blog. As you will see from my website if you ever go there, I suffer from the mechanic problem. The mechanic’s car is always broken type of thing, because he’s always busy with other people’s cars. If you are interested in Seam testing or Seam in general and would like to see a small app, something that’s not going to overwhelm you, definitely go there. It is self-contained so you should be able to give it a try.
Kito Sounds good. Thank you very much for chatting with us and for coming to the conference.
Daniel Thank you.
Announcer That's it for this edition of the JSFCentral podcast. The music for this podcast was composed and performed by Kito Mann. Thank you for listening.


RSS feed(all feeds)

The Editor's Desk
Podcasts
Inside Facelets
In the Trenches

Site version 1.83  Report web site problems

Copyright (C) 2003-2014 Virtua, Inc. All Rights Reserved. Java, JavaServer Faces, and all Java-based marks are trademarks or registered trademarks of Oracle Corporation. in the United States and other countries. Virtua, Inc. is independent of Oracle Corporation. All other trademarks are the sole property of their respective owners.