Matthew Plant

Greenhorn
+ Follow
since May 07, 2008
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 Matthew Plant

Thanks, Will this work even if the database is quite large?
13 years ago
Hi,

I am trying to change the implementation of a complex method in the service layer of a Spring web application. The method basically contains a big loop which uses a DAO class to load, save and update objects in a database.

As I don't want to break anything I am trying to write a unit test for this method which I can run before and after my changes to test the results.

The problem is that while my method does return an object with values that can be asserted. The whole functionality of the method relies on the DAO layer and heavily depends on the current state of the database to be able to predict the results.

I have though about providing a mock object for my DAO class but the only way I can see that working is to replicate the functionality of the database in that class. I though mock objects basically did nothing so would this then be a Stub? Anyway this would take ages to implement and would likely need testing itself!!!

I'm also not sure how to layout the test class. Should I create one test class for the entire service class that contains my method (in which case test setup code will have to go into the individual test methods making then huge), or as or one test class just for this method with a specific setup method which does all the pretest work.

Is it even possible to write a unit test for this method which I don't have to throw away once I've written it because I can't garantee the state of the database?

Any advice?
Thanks
13 years ago
Hi,
Am trying to design a simple GUI which is basically a form with labels down one side and various components down the other all nicely aligned.

This seems to be proving really difficult and I'm sure this kind of layout is a common one.
Is there an easy way of arranging components into a simple form?
Maybe someone could point me in the right direction.

Thanks.
15 years ago
You would use a static initialiser to set up static variables before you access them via your static methods.
15 years ago
Under Windows, Goto control panel, system, advanced, environment variables. Path and classpath will probably already be under system variables, you can edit these.

classpath maybe set to "." which means the current directory.

you can also set classpath at runtime when you run java.exe by using the command line switch "-cp [classpath]"

If your project uses external jars, you may need to set this switch when you use javac to compile your classes so javac can located the classes within the jar file.
CLASSPATH is where java applications look to find compiled classes (ie. *.class, *.jar)

PATH is where the system looks to find executables (ie. java.exe, javac.exe) so when you type java from the command line, it can find it and you don't have to change to the correct directory first.
This seems to be the error you encountering "Cannot retrieve definition for form bean AddressForm"

Have you defined a form bean called AddressForm in struts-config.xml?
15 years ago
What do you mean by static block?

Do you mean a static initialiser? eg.

static {
// Do something.
// Do something else.
}

If so, this is like a contructor but is called when the class is loaded rather then when the object is contructed.

If I have misunderstood, I apologise.
15 years ago
Thanks guys.
Sounds like a can of worms, I guess have to do a bit of research
15 years ago
I'm sorry what is a HMAC?
Any advice on how to do this in a very simple way.
15 years ago
Hi,
I need access to my web application session from an applet but I don't think this is possible (correct me if I am wrong here) so...

I want to pass a user id to applet as a parameter but I am worrying that a user might able to change the applet parameter and resubmit the request getting another users data.

Is this something I should be worrying about?
can I hash the paramater value?

I'm using struts.
Thanks.
15 years ago
Ha ha, there's a reason you're a sherif and i'm a green horn.

Cheers
15 years ago
I have a simple applet within a JSP.
The applet extends JApplet and overides its paint method to draw some simple shapes to the screen.

Problem is if I minimise the browser window and re-open it or scroll the applet off the page briefly then it never re-paints itself so you end up with a grey box.

I though paint was called by the system as required.

Am I wrong?

Thanks.
15 years ago
I finally got it to work and I haven't broken struts!!!
Thanks for your help with this.

Think I was mostly doing things right but a couple of things tripped me up...

1. I think I was initially missing a slash in the servlet mapping which was breaking struts.

2. Then when I got the networking code sussed and the applet worked standalone but not embedded in a JSP I realised struts was helpfully sticking ".do" onto the end of my request to the servlet.

Changed the servlet mapping to the following and it ALL worked.

<servlet-mapping>
<servlet-name>custom</servlet-name>
<url-pattern>/Custom.servlet</url-pattern>
</servlet-mapping>

Now if I can only remember what I was originally trying to achieve... ;-)

Thanks again, great forum.
15 years ago
Erm something like:

<servlet>
<servlet-name>custom</servlet-name>
<servlet-class>test.servlet.CustomServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>custom</servlet-name>
<url-pattern>/custom</url-pattern>
</servlet-mapping>

not quite sure how the url pattern should look for what I am trying to do...

Also I noticed the struts action servlet defination has this extra bit within the servlet tags. <load-on-startup>2</load-on-startup>. Maybe I need one of those in my servlet definition?
15 years ago