Chris Corbyn

Ranch Hand
+ Follow
since Jan 14, 2007
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Chris Corbyn

I have a series of Amazon EC2 instances I wish to hold the addresses for in my build.xml file. For a particular target I would like to loop through all of these addresses and issue a command to the server. I can do it for one at a time; but I'm not sure how to create the equivalent of a Collection in the build.xml and then how to loop through that Collection.

In pseudo:



I'm sure it's staring me in the face when reading the documentation but I'm missing it. Any hints?
15 years ago
I think the wording is perhaps a bit misleading. "User" refers to the local client I assume, and in which case if you only read from the server when the local client sends a message then you would only ever know if the remote client in the chat has said anything once you say something.
16 years ago
I'm using jMock (which is awesome by the way) for my mock objects because it's simple to generate the mocks and make expectations with it.

jMock allows me to create mock objects from the servlet spec interfaces with a few lines of code so I'm happy for now There's actually only a handful of objects which *need* to be mocked/stubbed in order for things to work.

Originally posted by Gabriel Claramunt:
Can you use JSF? If you insist, IS part of J2EE and you only need POJOs, very easy to test. If you experienced the pain of working with plain JSPs and servlets, JSF is a blessing



Right now my J2EE knowledge extends to: Servlets, JSP, Tag Libraries (and JSTL) and EL. JSF was on my "to learn" list but with what you're saying I should really look at that now then

Cheers.

PS: Oh yeah, I'll never (ever ever ever) need to test anything in my JSP code Just templates, that's all I use JSP for

Originally posted by Peer Reynders:
JavaWorld: Testing J2EE applications (2004-Aug)
J.B. Rainsberger (Diaspar): Test-Driven J2EE

[ September 10, 2007: Message edited by: Peer Reynders ]



I've only got to the 4th page in that article on JavaWorld and already I feel like they're testing too much. I personally don't want to simulate a web browser and/or a user clicking a link on a page right now. I'd rather create a mock of HttpServletRequest, set the request uri and some parameters and pass that mock to my servlet while I test how it behaves. I may find a need for that depth of testing later once I start testing pages built inside my framework, but not now

I'll finish Frank's article then I'll grab JUnit and wrap my head around how people create Mocks in Java and I'll get started

Originally posted by Stan James:
Spring's inventor wrote about the power of POJOs - Plain Old Java Objects - before he did Spring. Spring dependency injection is just one way to isolate your POJOs from J2EE. You can do it on your own.

One idea is to reduce the classes that know about HTTP, Session, Request, Response, EJB, etc. to minimal gateways. They do as little as possible before handing off responsibility to classes with no J2EE imports. For example, a servlet might copy all the request parameters into a HashMap and call a POJO. (You asked about doing this "without a framework" but you're really building a smallish framework at this point.)

Now you don't have a J2EE question any more. You can TDD all your POJOs without thinking about servlet or EJB containers.

Is that the kind of thing you're looking for?



This is one approach I considered taking, but J2EE is J2EE. It offers a lot and (IMHO), hiding it from the commands/actions would be a waste. I've taken a K.I.S.S approach with my non TDD version and simply give ServletContext, ServletRequest and ServletResponse to the individual actions controllers before heading off to a View (JSP) -- if requested.



I'm not planning on Unit Testing what I've already written because I don't find that particularly useful. I know it works. I find unit testing more useful as a driving force in development so I'll be going back to scratch.

It would be a shame to have to hide the fact the environment is J2EE by writing my own objects for things that J2EE already provides. Really it wouldn't be too much effort to create mock objects from the APIs in the spec and test with those but I didn't really know if that was a done thing. It's fortunate J2EE has such a complete spec which you can rely on.

Peer, thanks for the links I'll have a read Frank, I still didn't get through your second article because my boss spat his dummy out when he caught me reading it while I was supposed to be working on a PHP project Meh, I don't care, I leave for Oz in 2 weeks

Thanks again guys.
Reading it now thanks. I read the first one which was aptly agile though no mention of tests just yet having only just written a little interface. I'll keep going I'm aware that some of the content is out of date, being over 4 years old now

PS: I really like browsing/reading the Journal but it looks like things are on a slow down lately... unless I'm missing where the 2007 articles are?
I create screen.xml files for this... one per-screen in, for example /WEB-INF/screens/documentation/contents.xml:



Now just use XPath to query what you need. I have a ScreenFactory object which creates a simple bean from the configuration. I also store 'fragments', CSS files, JS files and Meta data in here.
16 years ago
JSP
I've come from a PHP background where I used to develop with TDD religiously but moved to Java a couple of months ago. I feel like I've gotten to grips with the language enough to at least get back into Unit Testing. I've tried searching around for some inspriation on how to approach test driven development within a servlet environment but all I keep coming across is spring and hibernate articles....

Does anyone have any good links to articles which provide some insight into using JUnit on a J2EE server without being tightly bound to a particular framework (in my case I'm writing my own framework as part of my self-teaching).
I updated it to use an indexed setter system like so:



It's implemented like this:



I have dynamic menu options which are displayed and they are colorful buttons on a dark background. I wanted to avoid the crazy logic determining what color to use in the JSP

16 years ago
Drum roll please.....

<navigation>
...
</naviagtion>

That was the root of my problem. I've got fat fingers. Now suddenly I don't care if I have to put try/catch around every call to DocumentFactory.getDocument() because I'd rather know what the problem is than just having a null return value
16 years ago
EDIT | Scrap that. Confused
[ September 09, 2007: Message edited by: Chris Corbyn ]
16 years ago
In my servlet/JSP app I have a handful of XML files which all sit in /WEB-INF and get accessed from various different places (Filters, Controllers, Beans...). I started out using servletContext.getResourceAsStream() and then using DocumentBuilder to create a new Document object.

The problem with that was that I was:

a) Needing to pass ServletContext around all components which need to read XML files
b) Creating multiple instances of the same Document needlessly.

So with that in mind I set about trying to create a singleton called DocumentFactory which contains ServletContext and a Map of already built Documents.

Early on in the FrontController invoke: DocumentFactory.getInstance().init(servletContext).



This worked great when I was just working within my servlet. But just recently I tried using it in a JavaBean from a JSP file. It always returns NULL for any document that wasn't used previously. The only difference between trying to use it from a JSP/JavaBean and using it from the servlet is that RequestDispatcher.forward() has been called.

I've pinned the problem down to this line:



Is there a reason why servletContext (from the Servlet, before forward() was called) will not fetch resources *after* forward() has been called?

Is that a more elegant way to do what I'm trying to do?

Basically I just want a convenience class that can grab me a XML file from WEB-INF and can be accessed from anywhere within the current context.

Thanks for the help if anybody actualy gets to the end of this thread
16 years ago
Both points taken on board and agreed with I'll rewrite the bean. I think I need to implement a getNext() method because I do need some way of making it iterate cyclically.

The reason it's needed is for alternating colors (but more than just two colors). I wanted to avoid too much complex bitwise logic inside the JSP itself.

Rather than the typical boolean negation or modulus operations I can just keep using ${color.next} and let the bean deal with that logic.
16 years ago