aspose file tools*
The moose likes Servlets and the fly likes Testing Servlet Code in XML 1.0 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Testing Servlet Code in XML 1.0" Watch "Testing Servlet Code in XML 1.0" New topic
Author

Testing Servlet Code in XML 1.0

Michele Smith
Ranch Hand

Joined: Oct 27, 2010
Posts: 420
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

Joined: Feb 26, 2001
Posts: 4717
    
    7

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.


Junilu - [How to Ask Questions] [How to Answer Questions]
Michele Smith
Ranch Hand

Joined: Oct 27, 2010
Posts: 420
Hello, I imported the servlet into the following servlet, and wondered if you think this is sufficient:

Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4717
    
    7

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

Joined: Oct 27, 2010
Posts: 420
Sorry, I don't know what you mean.

Could you be more specific?

Thanks,
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4717
    
    7

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

Joined: Oct 27, 2010
Posts: 420
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

Joined: Feb 26, 2001
Posts: 4717
    
    7

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Testing Servlet Code in XML 1.0