Jason Ferguson

Ranch Hand
+ Follow
since Sep 16, 2007
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 Jason Ferguson

I'm trying to write an web application that takes advantage of X.509 authentication. I want to make sure I am straight on what needs to be done.

First, in my applicationContext.xml file, I need to add the following lines:



On the database, I need to have populated User and Authorities tables. The username in the User table needs to be the CN from the X.509 certificate.

Next, I need a model/value object which implements UserDetails.

Next I need to implement UserDetailsService.

Once all of this is done, the SecurityContext will contain an Authentication object.

I then go back to the applicationContext.xml and set up the authorities by adding this line (and others) to the section:



It just seems a bit too easy, and I'm still scarred from a failed attempt to do this from the ACEGI days.

Jason
7 years ago

Originally posted by Jeanne Boyarsky:
Jason,
I'm glad you got past it. For the future, note that requires a clumsy hack in order to be made testable is often crying out to be refactored.



Already working on it. I've moved the mail code into a separate (protected) method, and will be moving the code to create the notification message into yet another method.
10 years ago

Originally posted by Eric Nielsen:
First it looks like you're using an ancient version of EasyMock... Is that intentional?



Its an unfortunate necessity. EasyMock 2.X requires Java 5.0. It seems that the only way to get my app server upgraded out of the stone age would involve violence, and I've decided that it's not worth ending up in jail for.


Seems like you're trying to do the wrong things in the setUp method. I'd suggest restructuring it like: (using the a more modern (but still ~2.5 years old EasyMock))


// Snipped out code

You're only testing are the correct calls proxied through to the DAO (and any other business logic/manipulation you need to do). Since you're mocking the DAO, there's no real need to build up a list of cbts anywhere, I haven't ripped it out yet, but its really not needed... Even for testing exceptions/duplicates, it won't be needed since all you need to do is set the expectation to be expect().andThrow().... to check if you handle those cases correctly.




Okay, back to the books then. I'm only a couple of days into doing unit testing, and haven't used expect().andThrow() yet.
10 years ago
I have figured out quite a bit since my earlier post, but am still stuck on how to test methods that insert, update, or delete a method from the database.
(Query methods I can test pretty well).

I'm working on a CBT application, with a layer system that looks something like this:

- Controller (Struts 1.X Actions)
- Service Layer
- DAO Layer

Just randomly, I decided to start with the Service Layer (actually, not so randomly... my local database on my dev machine isn't configured yet, so I can't test the DAO layer).

Here is what I have so far:

CbtService Interface:



Here's the unit test:



Since I enter reply mode in setUp(), I don't think I can add a new member to cbtList in testAddCbt(). And since I can't add another member there, I can't remove it in testDeleteCbt().

Does anyone have any ideas for testing these methods?
10 years ago
Jeanne,

I finally moved past that last night, by using EasyMock to mock JavaMailSender.

The only problem was that I ended up changing the return type of the method to return a rather odd Map that contained an array of all the SimpleMailMessage objects generated by the class and a few other items generated internally by the method. I'm not overly happy with that, but it's testable :/

Jason

Originally posted by Jeanne Boyarsky:
Jason,
Before you worry about the mail sender, can you write a test that calls the DAO and has the DAO return an empty list? This gets you set up with whatever mock objects library you are using with a simpler case since it skips the whole loop.

Once you have that, you have demonstrated mocking out an interface. org.springframework.mail.javamail.JavaMailSender is an interface too. Which means you can try using the same techniques. NOte that while MailSender is injected by Spring when you run "for real", it is not injected during unit testing. It is your unit test's responsibility to inject it.

10 years ago

Originally posted by chintan ramavat:
Hello friends ,

interesting question to all experts out there, I have one drop down and when user clicks i need to get data using ajax with java classes. but how to load data using ajax and place that using specific format.

the structure is using Ajax, JSON and JAvascript

- any help is much appreciated
- thanks



Chintan,

Are you attempting to populate the contents of a second <SELECT> element based on input from the first? This is commonly referred to as a chained selector.

You cannot do this with only Javascript (note: AJAX and JSON are not programming languages. AJAX refers to a methodology, and JSON is a data format in the same way as XML is). You need a Java class to do this on the server side. I tend to use a struts action to do it. You may also wish to take a look at json-lib (http://json-lib.sourceforge.net), which converts Collections, Maps, and individual objects to JSON.

I also have a chained selector javascript function, which relies on the Prototype javascript library. Let me know if you are interested.

Jason

Originally posted by Henry Wong:


It shouldn't be that hard to write one... Just create a Comparator that takes strings, whose compare() method, converts the string to either int, float, or double, and then route the request to the Integer, Float, or Double class as the comparator.

Henry



I hate when I get in a hurry and leave one of the most critical parts out.

Suppose you are sorting addresses:
- 1 Main St
- 7 Main St
- 9 Main St
- 11 Main St
- 30 Main St

A simple string sort would turn this into:
- 1 Main St
- 11 Main St
- 30 Main St
- 7 Main St
- 9 Main St

So what we have here is a two part comparison: the number and the string. The number is the more important part, but after the number comes the text part of the string.

Is there a better way than splitting the string (probably via regexp)?
10 years ago
Does anyone have a Comparator implementation that can sort String numbers correctly?

Example: the list

1,2,11,8,7,12

Should sort to:

1,2,7,8,11,12

Instead of:

1,11,12,2,7,8

Jason
10 years ago
Okay, from C: or root, I have a "Programming" directory.

Under Programming, I have the following subdirs:

- Build Tools
- Libraries
- Servers
- SVN

Build Tools breaks out like this:

- Ant
- Maven

Libraries contains a subdirectory for the dist files for all of my dev libraries (the big three of struts, spring, and hibernate, and about 4 dozen others). Each dir will contain the library jar, source, and javadocs.

Servers breaks out to:
- Application
- Database

In application, I tend to keep OC4J and Tomcat. Database contains MySQL and/or any other database server I need.

SVN is my project specific files that I check out of subversion.

The main advantage of this is that transporting between machines is easy: copy the Programming dir to a flash drive and copy to whereever I need.

Disadvantages:
- Size. This will NOT fit on a 1gb flash drive
- Redundancy. Several libraries have dist folders that contain dupes of libraries I already have.

This is the best method I've found. However, I'm wanting to ask: does anyone have any suggestions for improvement on my method?

(Moderators: if there is a more appropriate forum, please feel free to move this topic).
10 years ago

Originally posted by Christophe Porteneuve:



Obviously, I would strongly recommend my book and its blog, too�



Seconded... an EXCELLENT book, which I bought before knowing the author was a regular here. I practically lived in the Builder chapter for a week due to needing to dynamically build a rather complex form.
Hmmm, I may have to take a closer look at Groovy, but not necessarily for the use case you gave.

You state that with a POGO, getters and setters are generated automatically. As an IDEA user, its not as if I actually write the getters and setters out manually (its more like: define variables, alt-insert, generate setters and getters). Since this is automated for me, I'd tend to do it that way and not deal with any particular performance issues (although this one is probably minor).
10 years ago
Hi Scott,

I've seen the hype, and I can type the word Groovy into google just fine.

However, can you give a real-world-ish use case that caused you to say "Hey! Groovy made for a better solution than Vanilla Java!"

I tend to write relatively simple webapps based on a Struts/Spring/Hibernate architecture, and have alot of stuff planned out to learn. Why should I put Groovy on that list and/or prioritize it over other items?
10 years ago
Okay, gotta go with Ben on this one. I need to remember the dead seagull analogy.

However, if you want a simple way to do this, check out the DisplayTag library at http://displaytag.sourceforge.net. While its primary purpose is to lay out information into HTML tables, read further into the docs for exporting to other formats, including Excel and PDF.
10 years ago
JSP
Okay, first some nitpicking:

You are mixing "county" and "country" as names. This can lead to massive confusion since the words are similar but have different meanings.

Now, I'm assuming that you have a Domain Object named Country, with fields such as "id","name" (or "countryname"), etc. However, in your Expression Language (EL) in <coreut name="">, you are specifying the entire object. This is calling the default "toString()" of that object.

Instead, use an EL something like this: ${country.name}, specifying which attribute of the country object to output.

Also, in order to keep myself consistent, I usually create an interface for my Domain Objects:



I tend to use alot of dynamically created <option> tags, and one of the things this interface allows me to do is always know what the option tags will be populated with. (Also, sometimes I just get going too fast and will name my id and name fields badly).

Jason

Originally posted by ujjwal soni:
Hi,

I am unable to display country list from database on my jsp page. Instead of the country values, i am getting the below output onm my jsp page

-----------Output Start---------------------
Project.Domain.Admin.CountryService@d6a0e0 Project.Domain.Admin.CountryService@dbf04d
-----------Output End-----------------------

The code on my jsp page is as under.

<%@ page language="java" pageEncoding="ISO-8859-1"%>
<%@ include file="/WEB-INF/jsp/Admin/include.jsp" %>

<core:forEach var="county" items="${CountryList}">
<coreut value="${county}"/>
</core:forEach>

I am using spring Controller & i am sending the List object in HttpRequest parameters of ModelAndView return type.


Regards,

Ujjwal Soni

10 years ago
JSP
Okay, first some nitpicking:

You are mixing "county" and "country" as names. This can lead to massive confusion since the words are similar but have different meanings.

Now, I'm assuming that you have a Domain Object named Country, with fields such as "id","name" (or "countryname"), etc. However, in your Expression Language (EL) in <coreut name="">, you are specifying the entire object. This is calling the default "toString()" of that object.

Instead, use an EL something like this: ${country.name}, specifying which attribute of the country object to output.

Also, in order to keep myself consistent, I usually create an interface for my Domain Objects:



I tend to use alot of dynamically created <option> tags, and one of the things this interface allows me to do is always know what the option tags will be populated with. (Also, sometimes I just get going too fast and will name my id and name fields badly).

Jason

Originally posted by ujjwal soni:
Hi,

I am unable to display country list from database on my jsp page. Instead of the country values, i am getting the below output onm my jsp page

-----------Output Start---------------------
Project.Domain.Admin.CountryService@d6a0e0 Project.Domain.Admin.CountryService@dbf04d
-----------Output End-----------------------

The code on my jsp page is as under.

<%@ page language="java" pageEncoding="ISO-8859-1"%>
<%@ include file="/WEB-INF/jsp/Admin/include.jsp" %>

<core:forEach var="county" items="${CountryList}">
<coreut value="${county}"/>
</core:forEach>

I am using spring Controller & i am sending the List object in HttpRequest parameters of ModelAndView return type.


Regards,

Ujjwal Soni