Archive for June, 2006


icalendar and Rails

Monday, June 26th, 2006

I’ve recently used icalendar to output an ical from a Rails app I’m running. It’s incredibly simple, here’s what I did:

  1. Create an ical_controller:
    script/generate controller ical
  2. Add a method to generates the events:
    require 'icalendar'
    
    class IcalController < ApplicationController
    
      caches_page :competitions
    
      def competitions
        @cal = Icalendar::Calendar.new
    
        Competition.find_all.each do |comp|
          event = Icalendar::Event.new
          event.start = comp.date
          event.end = comp.date
          event.summary = comp.name
    
          @cal.add event
        end
      end
    
    end
  3. Create a view (app/views/ical/competitions.rhtml):
    < %= @cal.to_ical %>
  4. Install icalendar into your vendor directory:
    cd vendor
    gem unpack icalendar
  5. Add the necessary dependency to config/environment.rb
    require 'icalendar-0.96.4/lib/icalendar'

And that’s it. Once deployed you can access your ical and import it anywhere. I’ve tried mine out with Google Calendar and it imported without a hitch. One deficiency in icalendar is the inability to give a name or description to the calendar itself, so you’ll have to rename it in your calendar application. The only caveat in the above code is the caching directive in the controller. I’ve cached the entire page because the events don’t change frequently. To expire the cache you’ll have to add the following line to the appropriate controller methods where your events changes:

expire_page :controller => "ical", :action => "competitions"
Spread the word: Technorati related  |  del.icio.us bookmark it!  |  submit icalendar and Rails digg.com digg it!  |  reddit reddit!

Who’s in charge of distributing mobile games?

Monday, June 26th, 2006

John Carmack is making mobile phone games these days. His current one is an RPG called Orcs and Elves. It looks pretty cool:

so I figured I’d give it a go. It’s a mobile phone game so I thought I should be able to get it pretty quickly, how wrong I was. I couldn’t buy it directly off ID, it’s being published by EA Mobile. No problem I go to their site, there it is for $2.99, I click Buy Now. I’m then told I need to select my mobile provider, but it only lists American ones. I’m on the American site, so I switch the to UK one. Orcs and Elves is nowhere to be found, at least on the front page. I use their game finder, which requires me to select my provider. I select Vodafone, it brings me to a page that tells me I need to go to the Vodafone website on the web or on my phone. They can’t even tell me which EA games are available through Vodafone.

I go to the Vodafone games site. I can’t see Orcs and Elves, and they force me to find games by browsing by phone model and type of game. I try the search, it comes up with nothing. I’m not sure if it searches the games, so I try searching for their current top game, FIFA 2006. There’s one result and it directs me to this page (a 404 for those too lazy to click). Clearly their search is broken so I end up browsing, thankfully there’s an EA category, because the Action/Adventure has 11 pages to browse through.

End result? They don’t have it. They do have Doom RPG, ID’s first attempt at a mobile game, which has good reviews, but I’m not that interested in a turn based version of Doom. Even if I was it costs £5.00, three times more than I could buy the newer game if I was in America! Why is getting a hold of this game so difficult? I don’t buy it in a shop, I don’t get a CD, I get it off the Internet, and with a phone connected to the Internet I should be able to get it virtually anywhere. But instead I’m forced to wait for my mobile provider to get it, then get charged a huge markup because I’m in the UK and can only get it through them.

I hope this isn’t a sign of how the mobile Internet is going to work for all media.

Spread the word: Technorati related  |  del.icio.us bookmark it!  |  submit Who’s in charge of distributing mobile games? digg.com digg it!  |  reddit reddit!

Scala Might Have Legs

Saturday, June 17th, 2006

It looks like Scala is creeping into the mainstream. I definitely have to try it out on something ‘real’ soon. In the meantime here are some posts I’ve come across introducing Scala:

Spread the word: Technorati related  |  del.icio.us bookmark it!  |  submit Scala Might Have Legs digg.com digg it!  |  reddit reddit!

Software project late again?

Saturday, June 17th, 2006

This post brought a smile to my face. Sound familiar? ;)

Spread the word: Technorati related  |  del.icio.us bookmark it!  |  submit Software project late again? digg.com digg it!  |  reddit reddit!

Why do default implementations have such bad names?

Saturday, June 17th, 2006

Small rant about class names in Java, or more specifically classes who are the sole implementation of a particular interface. You go to the effort of coming up with a good name for your interface, e.g. IndexSearcher, but then the class name is enevitably one of:

  • SimpleIndexSearcher
  • IndexSearcherImpl

I’m guilty of this. There must be a better way to name our classes!?!

Don’t forget the other pattern, if IndexSearcher is your class, then IIndexSearcher is your interface. I hate that one too. :)

Spread the word: Technorati related  |  del.icio.us bookmark it!  |  submit Why do default implementations have such bad names? digg.com digg it!  |  reddit reddit!

Mock Objects and Testing Controllers

Saturday, June 17th, 2006

Up to now I assumed mock objects were just dummy objects you used in your unit tests when you didn’t want to use a real object, e.g. because the real object goes off and does something weird to a remote server. But apparently Mocks Aren’t Stubs, they are objects that allow you to do a different style of testing. Most units tests involve verifying the correct state of an object after an interaction, with mocks you can make sure the right methods are being called in the first place (see Martin Fowler’s article for more).

Most of the time I wouldn’t want to test the interaction, I just want to test an object, so mocks aren’t needed, but one area of my programming that always falls short of testing is controllers (in the MVC sense). They just require too many bits and pieces to get running that you eventually end up running your entire program for one test. Then I came across a couple of posts from Robert Chatley, who was in the same research group as me at university. He talks about using Spring’s mocks, as well as using JMock. That’s pretty much what I wanted to do and it all looked very easy.

Imagine we have a controller that does a Lucene search, we want to make sure it’s actually doing the search, here’s an example test case using JMock:

public SearchControllerTest extends MockObjectTestCase {
    private Mock searcher;
    private Mock logger;
    private SearchController controller;

    private MockHttpServletRequest request;
    private MockHttpServletResponse response;

    public void setUp() {
        super.setUp();

        this.mockSearcher = mock(IndexSearcher.class);
        this.mockLogger = mock(QueryLogger.class);

        this.request = new MockHttpServletRequest();
        this.response = new MockHttpServletResponse();
        this.request.setMethod(“GET”);

        this.controller = new SearchController();
        this.controller.setSearcher((IndexSearcher) searcher.proxy());
        this.controller.setQueryLogger(logger.proxy());
    }

    public void testSearch() {
        // Set our search term
        this.request.setParameter(“q”, “apples”);

        // Set our expectations
        Mock mockHits = mock(Hits.class);
        mockHits.stubs().method(“length”).will(returnValue(10));

        this.mockSearcher.expects(once()).method(“search”).will(returnValue(hits));

        // Do the request
        ModelAndView modelAndView = this.controller.handleRequest(this.request,
                                                                  this.response);

        // Verify our hits are stored in the model
        Map model = modelAndView.getModel();
        assertEquals(model.get(“hits”, mockHits.proxy());
    }

    public void testSearchWithNoResults() {
        // Set our search term
        this.request.setParameter(“q”, “apples”);

        // Set our expectations
        Mock mockHits = mock(Hits.class);
        mockHits.stubs().method(“length”).will(returnValue(0)); // We have an empty hits object

        // We’re not checking this time, just providing a stub to return our
        // hits object
        this.mockSearcher.stubs().method(“search”).will(returnValue(hits));

        // Because we have no results, we expect this query to be logged.
        this.mockLogger.expects(once()).method(“noHits”);

        // Do the request
        ModelAndView modelAndView = this.controller.handleRequest(this.request,
                                                                  this.response);
    }

}

In the above example we have two test cases, the first checks a search is executed correctly, and the second checks a special case where we log the query if it returns no results. We setup several mock objects, and for each one you have to state what calls you expect to be made on it, and what (if any) return value should be given.

There are two ways to get a mock to respond to a method, either with expects() or stubs(). Use expects if you want to test the method call. You’ll have to specify none(), once() or atLeastOnce(). Use stubs if you just want it to return a value, e.g. the length of our Hits object.

One nice thing about JMock is that the tests are sentence like, it’s very easy to read and understand what a line is doing, e.g. the searcher expects the method ’search’ to be called once. One (major) problem with JMock is the completely barren Javadocs. There is no documentation for the MockObjectTestCase class. This makes it pretty hard to write a test unless you’re copying someone else’s example.

This above example is very simple, but it’s possible to test error conditions, page flow and various other niggly bits of controllers, which means we can be confident of their behaviour and no longer have to ‘run and pray’.

Spread the word: Technorati related  |  del.icio.us bookmark it!  |  submit Mock Objects and Testing Controllers digg.com digg it!  |  reddit reddit!

ati-tv software ABBYY FineReader 8.0 Professional Multilanguage
ipod nana software ABBYY FineReader 8.0 Professional Multilanguage
easy fax software ABBYY FineReader Professional Edition 9.0 with Djvu Addon
encoder coding software Ableton Live 6.0.9
analytical system software ACD Systems Combo Pack
employee scheduling software Acronis Disk Director Server 10.0
eraise fundraising software Acronis Disk Director Suite 10.0
openeye software Acronis Disk Editor v6.0.360
gateway limited software Acronis Drive Cleanser v6.0 Build 383
tungsten software download Acronis Migrate Easy Deluxe v1.0.0.43
physics software Acronis & Paragon Universal Boot CD USB 2009 1.0
avatar server software Acronis & Paragon Universal Boot CD USB 2009 1.0
imaging software driver Acronis & Paragon Universal Boot CD USB 2009 1.0
software raid performance Acronis PartitionExpert 2003
legislative trackinig software Acronis Privacy Expert Suite 7.0
software listings Acronis Privacy Expert Suite 7.0
art software program Acronis Recovery Expert Deluxe
adams software forms Acronis True Image 7.0
free reservations software Acronis True Image Echo Server for Windows 9.5
panda antiviruse software Acronis True Image Enterprise Server 9.1.3666
microsoft excel software Acronis True Image Home 11.0
tape duplication software Acronis True Image Workstation 9.1.3887
free dayplanner software ActionScript 3.0 in Flash CS3 Professional Essential Training
raft software ActiveState Komodo IDE 4.2.0
software crises ActiveState Perl Dev Kit Pro 7
jq-210 download software Adobe Acrobat 7 Professional for Mac
audit software tracking Adobe Acrobat 7 Professional for Mac
smartist software Adobe Acrobat 7.0 Professional
callender software Adobe Acrobat 7.0 Professional
currency conversion software Adobe Acrobat 8.0 Professional
n95 remove software Adobe Acrobat 8.0 Professional
anderson software internet Adobe Acrobat 8.0 Professional
genealogy publishing software Adobe Acrobat 8.0 Professional for Mac
article distribution software Adobe Acrobat 8.0 Professional for Mac
map maker software Adobe Acrobat 9 Pro Extended
decisionbar software Adobe Acrobat 9 Pro Extended
timekeeping system software Adobe Acrobat 9 Pro Extended
knowledge mapping software Adobe Acrobat V 6.0 Professional PC
writing style software Adobe Acrobat V 6.0 Professional PC
management product software Adobe After Effects 6.5 for Mac
military packaging software Adobe After Effects 6.5 for Mac
knockout software Adobe After Effects 6.5 for Mac
mantel test software Adobe After Effects 7.0 Standard
pst repair software Adobe After Effects 7.0 Standard
pcr software customers Adobe After Effects 7.0 Standard
loopholes software testing Adobe After Effects CS3
ebay software tools Adobe After Effects CS3
volleyball statistic software Adobe After Effects CS3
autoquote software Adobe Atmosphere 1.0
medical documentation software Adobe Audition 2.0
software distrubitor Adobe Audition 2.0
6600 software program Adobe Audition 3.0
buy financial software Adobe Contribute CS3
apartment purchasing software Adobe Contribute CS3
define software application Adobe Creative Suite 2 Premium for Mac
autocad software review Adobe Creative Suite 2 Premium for Mac
pctools software Adobe Creative Suite 2 Premium for Mac
webchat software Adobe Creative Suite 2 Premium for Windows
book software store Adobe Creative Suite 2 Premium for Windows
software remote access Adobe Creative Suite 2 Premium for Windows
aor scanner software Adobe Creative Suite 2 Premium for Windows
software design article Adobe Creative Suite 3 Design Premium for Mac
microstudio 4.001 software Adobe Creative Suite 3 Design Premium for Mac
netscape 8 software Adobe Creative Suite 3 Design Premium for Mac
biblesoft software update Adobe Creative Suite 3 Design Premium for Mac
linux frontbridge software Adobe Creative Suite 3 Design Premium for Mac
code repository software Adobe Creative Suite 3 Design Premium for Win
acceleration software program Adobe Creative Suite 3 Design Premium for Win
clinical database software Adobe Creative Suite 3 Design Premium for Win
midi studio software Adobe Creative Suite 3 Design Premium for Win
aqura software Adobe Creative Suite 3 Master Collection for Mac
ezdata software Adobe Creative Suite 3 Master Collection for Mac
brightstore backup software Adobe Creative Suite 3 Master Collection for Mac
tk20 software Adobe Creative Suite 3 Master Collection for Mac
sequence analysis software Adobe Creative Suite 3 Master Collection for Mac
deployable spy software Adobe Creative Suite 3 Master Collection for Win
dprofiler software Adobe Creative Suite 3 Master Collection for Win
atm switch software Adobe Creative Suite 3 Master Collection for Win
hyperion software operations Adobe Creative Suite 3 Master Collection for Win
voice synthesis software Adobe Creative Suite 3 Master Collection for Win
iomega ghost software Adobe Creative Suite 3 Master Collection for Win
ups calculation software Adobe Creative Suite for Mac
oracle software Adobe Creative Suite for Mac
discount cad software Adobe Creative Suite for Mac
audio software forum Adobe Creative Suite for Mac
architectural renovation software Adobe Creative Suite 3 Master Collection for Win + Microsoft Office 2007 Enterprise
iphone 1.0.2 software Adobe Dreamweaver CS3
edsoft software Adobe Dreamweaver CS3
swing analysis software Adobe Dreamweaver CS3 for Mac
flowsheet software Adobe Encore CS3
lunix old software Adobe Encore CS3
software download drums Adobe Encore CS3
ficiton software Adobe Encore DVD 2.0
ebay software bidding Adobe Encore DVD 2.0
src software incorporated Adobe Encore DVD 2.0
amateur radio software Adobe Fireworks CS3
coin collectors software Adobe Fireworks CS3 for Mac
software package Adobe Flash CS3 Professional
convention software Adobe Flash CS3 Professional
picture software free Adobe Flash CS3 Professional for Mac
software circuit design Adobe Flash CS3 Professional for Mac
lenticular software crack Adobe Flash CS4
journal software engineering Adobe Flash CS4
webpage editor software Adobe Flash CS4
airframe business software Adobe Flex v.3.0.2
delmia software Adobe Flex v.3.0.2
freehand graphics software Adobe Font Folio 11
northrop resume software Adobe Font Folio 11
diabetes software pdas Adobe FrameMaker 7.0
istante software inc Adobe FrameMaker 7.0
vigilance software Adobe FrameMaker 8.0
software kinder preschool Adobe FrameMaker 8.0
dex drive software Adobe FrameMaker 9.0
de elementos software Adobe FrameMaker 9.0
software inspections Adobe FrameMaker 9.0
free cdrw software Adobe GoLive CS V 7.0 PC
ftp p2p software Adobe GoLive CS V 7.0 PC
transmit software Adobe GoLive CS2
becker data software Adobe GoLive CS2
fta firmware software Adobe Illustrator CS V 11.0 PC
liquids marketing software Adobe Illustrator CS V 11.0 PC
motorola v-180 software Adobe Illustrator CS2
explore anywhere software Adobe Illustrator CS3
outsourcing software solution Adobe InDesign CS V 3.0 PC
wntipcfg software Adobe InDesign CS V 3.0 PC
opengl software program Adobe InDesign CS2
nokia 6102i software Adobe InDesign CS2
free coloring software Adobe InDesign CS3
opp blackjack software Adobe InDesign CS3
astronomie software free Adobe InDesign CS4
monitoring email software Adobe InDesign CS4
development proposal software Adobe InDesign CS4
software cpu underclocking Adobe PageMaker 7.0.1
feko software Adobe Photoshop Album V 2.0
educational software seattle Adobe Photoshop Album V 2.0
learning measurement software Adobe Photoshop CS for Mac
flir software Adobe Photoshop CS for Mac
gps tracks software Adobe Photoshop CS v.8.0
free donation software Adobe Photoshop CS v.8.0
software updating freeware Adobe Photoshop CS2 for Mac
mountbridge software Adobe Photoshop CS2 for Mac
scream software seismic Adobe Photoshop CS2 V 9.0
software requirements plan Adobe Photoshop CS2 V 9.0
mpeg4 slideshow software Adobe Photoshop CS2 V 9.0
french genealogy software Adobe Photoshop CS3: Enhancing Digital Photographs
free software imac Adobe Photoshop CS3: Enhancing Digital Photographs
graphics benchmarking software Adobe Photoshop CS3 Extended
firewall software features Adobe Photoshop CS3 Extended
automatic prayer software Adobe Photoshop CS3 Extended
pine software examples Adobe Photoshop CS3 Extended for Mac