Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Testing Servlet Code in XML 1.0

 
Michele Smith
Ranch Hand
Posts: 421
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, I am inserting a method into a servlet, it is this:



How would I test for this specific parameter "parentid" in XML 1.0?

Thanks,
 
Junilu Lacar
Bartender
Posts: 7466
50
Android Eclipse IDE IntelliJ IDE Java Linux Mac Scala Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is nothing in the code you posted that relates to XML. Where does XML come into play here? If you're expecting 'parentId' values to be in XML format, then you should pass it to some other class that expects this and can validate it accordingly.
 
Michele Smith
Ranch Hand
Posts: 421
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, I imported the servlet into the following servlet, and wondered if you think this is sufficient:

 
Junilu Lacar
Bartender
Posts: 7466
50
Android Eclipse IDE IntelliJ IDE Java Linux Mac Scala Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Still not getting how this new code relates to the original code you posted and your question about "testing in XML." BTW, there are several "code smells" that make me crinkle my nose when reading this code.
 
Michele Smith
Ranch Hand
Posts: 421
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, I don't know what you mean.

Could you be more specific?

Thanks,
 
Junilu Lacar
Bartender
Posts: 7466
50
Android Eclipse IDE IntelliJ IDE Java Linux Mac Scala Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I could give more details but that would steer the discussion away from your original question. Do you want to digress or stick with the original question? Sorry for opening the door to the digression, but sometimes I can't resist pointing out code smells. Force of habit from doing daily code reviews.
 
Michele Smith
Ranch Hand
Posts: 421
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello I appreciate what you have said so far, it is food for thought, that is for sure. I will be sure and point this out to my team. I knew already that we had authentication problems.

I guess if you had the time, I would like to do both, to digress and to stick to the original question, only if you have the time, if not, can you revert back to the original question asked,

Thanks very much,
Michele
 
Junilu Lacar
Bartender
Posts: 7466
50
Android Eclipse IDE IntelliJ IDE Java Linux Mac Scala Spring Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For the original question: What exactly do you mean by "testing in XML"? Nothing you have given so far gives any context around that.

As for code smells:
1. "SelectFinanceReporting" is a poor class name. Class names should be nouns or noun phrases. In this case, you have a verb phrase.
2. getNavBarItem and getBanner methods have parameters that are never used.
3. getContent has a catch block but all it does is rethrow the exception. This does nothing useful; it's redundant and pointless. You should do more in the catch block or just remove the try-catch altogether.
4. You appear to be building XML content in a servlet. This responsibility should be given to another class, one that doesn't care about HttpServletRequest or HttpServletResponse or Context. Your servlet should just delegate to that class, passing in any information which it already extracted from the request. This makes the class that generates the XML easier to unit test. Hopefully, you are unit testing you code but my guess is your team is not doing much automated unit testing.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic