Waffle is moving from SourceForge to Codehaus. Additionally, and more importantly Waffle and VRaptor teams have decided to join forces.
The Waffle web framework will provide the core architecture for this joint effort. As the first step we have has begun porting Waffle to Codehaus (renaming it to use org.codehaus.waffle package instead of com.thoughtworks.waffle). Next we will begin to gradually port features from VRaptor. The vision of this effort is to create a larger and more consolidated community around a lean web application framework which honours the least-common-denominator principle.
May 22, 2007
March 20, 2007
RSpec:Rails - How to mock partials when testing a View.
When developing Ruby on Rails (RoR) applications I prefer to use RSpec over the built in testing framework provided with RoR. The biggest benefit is that RSpec easily allows you to test your application layers in isolation (e.g. when testing a Controller you should not be interested in testing the Model). So with that in mind when I am testing a View I am only interested in testing that View and not any of the potential partials that View may try to render.
Suppose we have the View /example/hello_world.rhtml:
Often in RSpec when testing a view such as this the spec ends up testing the partial as well. This is less than desirable because any change to the partial could break test for other views that render that partial. After some investigation I discovered that I could mock the calls to <%= render :partial => 'address'... %>. Have a look at the following spec:
You can grab a handle to the ActionView through @controller.template as is done in the example above. Then I mock the call to the 'render' method only when the 'address' partial is requested.
As you can see my spec only needs to be concerned with testing the /example/hello_world.rhtml View. The partial will have it's own separate spec. The side effect is that my view specification becomes much more manageable and far less brittle.
Suppose we have the View /example/hello_world.rhtml:
<div id="person">
<h2 class="title">Hello <%= @person.name %></h2>
<%= render :partial => 'address', :locals => {:person => @person} %>
</div>
Often in RSpec when testing a view such as this the spec ends up testing the partial as well. This is less than desirable because any change to the partial could break test for other views that render that partial. After some investigation I discovered that I could mock the calls to <%= render :partial => 'address'... %>. Have a look at the following spec:
specify 'should call mock and not the actual partial' do
person = mock('person')
person.should_receive(:name).and_return('Regan')
assigns[:person] = person
# Mock the call to 'render_partial'...
@controller.template.should_receive(:render).with(:partial => 'address', :locals => {:person => person})
render '/example/hello_world'
response.should_have_tag(:h2, :content => "Hello Regan")
end
You can grab a handle to the ActionView through @controller.template as is done in the example above. Then I mock the call to the 'render' method only when the 'address' partial is requested.
As you can see my spec only needs to be concerned with testing the /example/hello_world.rhtml View. The partial will have it's own separate spec. The side effect is that my view specification becomes much more manageable and far less brittle.
October 05, 2006
ParaNamer support in Waffle as an alternative to annotations
The latest release of Waffle (0.7) can now fully support ParaNamer as an alternative to annotations. ParaNamer provides "method parameter name access for versions of Java PRIOR TO Java 7.0". ParaNamer combined with Waffle will allow you to utilize your ActionMethod parameter names directly. In the example below Waffle will use "itemId" and "quantity" to resolve the arguments for the void removeFromCart(Long, int) action method.
For complete details on this please see the documentation on Waffle ActionMethods.
public class ShoppingCartAction implements Serializable {
...
// No annotation is necessary when utilizing ParaNamer
public void removeFromCart(Long itemId, int quantity) {
cart.remove(itemId, quantity);
}
}For complete details on this please see the documentation on Waffle ActionMethods.
October 04, 2006
Describing Waffle with one picture
The Waffle team has been busy over the last few months adding features and simplifying the overall design. Much of the documentation has been updated to reflect these changes. Many times however, it is easier to describe something with a simple drawing or a picture. So have a look at the following to get a clear idea of what Waffle provides:
Ruby on Cygwin error (*** unable to remap)
I had an annoying issue occuring when running Ruby under Cygwin. The error was reproducable every time that I attempted to run the ri command.
I was finally able to resolve the issue with the following steps:
C:\cygwin\lib\ruby\1.8\i386-cygwin\readline.so to same address as parent(0x370000) != 0x2760000
C:\cygwin\bin\ruby.exe (3132): *** unable to remap C:\cygwin\lib\ruby\1.8\i386-cygwin\readline.so to same address as parent(0x370000) != 0x2760000
I was finally able to resolve the issue with the following steps:
- exit from cygwin
- enter the dos command prompt
- cd to you cygwin bin directory (c:\cygwin\bin)
- run ash rebaseall
- restart cygwin ... problem solved
June 19, 2006
Waffle: define a default event in your Action
Waffle now provides a new DefaultEvent method level annotation for use in your Actions. This allows you to mark a particular method as the default event to fire when no other event was signalled. This is particularly useful when a user is directed to a page for the first time. Until now, the previous page was responsible for setting up for the page that preceeds it. Either that or all links within your application would be required to define exactly which event should be triggered through request parameters (e.g. "/application/myaction.htm?EVENT=init|{request}").
The following Action example (MyAction) has its init(HttpServletRequest) method annotated as the default event.
Notice the value "{request}" set on the DefaultEvent annotation. This provides a hint to Waffle to help it satisfy the method arguments. If you are familiar with Waffle you should realize that this is similar to how events are defined from Views. This in fact is not just similar it is identical. You can define the event arguments for the DefaultEvent annotation in the same way described in the Advanced Events section of the tutorial.
The following Action example (MyAction) has its init(HttpServletRequest) method annotated as the default event.
public class MyAction {
@DefaultEvent("{request}")
public void init(HttpServletRequest request) {
// ...
}
}
Notice the value "{request}" set on the DefaultEvent annotation. This provides a hint to Waffle to help it satisfy the method arguments. If you are familiar with Waffle you should realize that this is similar to how events are defined from Views. This in fact is not just similar it is identical. You can define the event arguments for the DefaultEvent annotation in the same way described in the Advanced Events section of the tutorial.
April 19, 2006
Waffle on TheServerSide.com
Waffle was recently posted on TheServerSide.com under the heading Another Rails-like web framework: Waffle. I was happy to see it posted and really appreciated the responses from those that are interested in Waffle.
I'm grateful for the comparison of Waffle to Ruby on Rails but Waffle is NOT a Java version of Rails. I think the only viable comparison I can make between Waffle and Ruby on Rails is:
I'm grateful for the comparison of Waffle to Ruby on Rails but Waffle is NOT a Java version of Rails. I think the only viable comparison I can make between Waffle and Ruby on Rails is:
- convention based
- simplicity
- both take advantage of their respective languages
- increased development productivity
March 28, 2006
Try using FreeMarker to generate XML documents
Generating XML from code is a very common development task. There are a multitude of ways it can be accomplished. Recently, at a client, we needed to generate an XML message which had to conform to a rather complicated XML schema. We already had an object model that worked well with our code base. We considered using XML binding API's like:
Each of these had its own limitations which reduced their feasibility within our application. Next we considered hand-coding the XML directly with API's like:
The amount of code required to create an XML document with these API's was excessive. Code like this was not fun to write nor easy to follow.
So we decided to take a different approach and use a templating engine, specifically FreeMarker. Using FreeMarker to generate the XML response messages turned out to be a great decision. This is a list of some of the advantages we have noticed:
Each of these had its own limitations which reduced their feasibility within our application. Next we considered hand-coding the XML directly with API's like:
The amount of code required to create an XML document with these API's was excessive. Code like this was not fun to write nor easy to follow.
So we decided to take a different approach and use a templating engine, specifically FreeMarker. Using FreeMarker to generate the XML response messages turned out to be a great decision. This is a list of some of the advantages we have noticed:
- The FreeMarker template we wrote to create the XML response message is an XML document. This simple fact should not be overlooked.
- Easy to integrate into any application. Very little code was required to utilize FreeMarker in our application.
- Excellent performance.
- The built-in functionality that FreeMarker provides is very powerful.
Tutorials for Waffle
I have been spending my free time updating Waffle with functionality and documentation. Two tutorials have been added to the Waffle web site which should provide a good overview of how to use Waffle and what makes it different.
The examples in the tutorials show how to use Waffle with JSP's. This was done based on feedback I have had when talking about Waffle with developers. At this point you should get latest Waffle code directly from subversion and build it with Maven 2.0.
I would appreciate any comments or feedback you could offer.
The examples in the tutorials show how to use Waffle with JSP's. This was done based on feedback I have had when talking about Waffle with developers. At this point you should get latest Waffle code directly from subversion and build it with Maven 2.0.
I would appreciate any comments or feedback you could offer.
February 22, 2006
Sourceforge and subversion
I logged into SourceForge.net today and noticed that a Subversion link was now available when I went to the Administration page. I'm not sure when this feature became available or how long it took me to actually notice it but I think it is great news that SourceForge now provides it.
Look for Waffle's code base to be moved to Subversion shortly.
Look for Waffle's code base to be moved to Subversion shortly.
February 14, 2006
FreeMarker support in Waffle
I recently added FreeMarker support as another option for creating Views in Waffle. FreeMarker is very similar to Velocity but seems to be more powerful. One of the nice features of FreeMarker is that it will point out the errors in your scripts. Velocity basically ignores any problems you may have, while FreeMarker displays an error message directly in your html that pin-points (line and column number) where the problems is located. Additionally FreeMarker actually allows you to reference JSP tag libraries within your FreeMarker scripts. That should allows for some nice flexibility. Take a look at the FreeMarker Servlet Documentation for further details. And take look at Waffle to see how easy it is to create web frameworks when you don't have to learn a proprietary XML syntax or new UI language.
Next task is to document how to create Waffle application with JavaServer Pages (JSP).
Next task is to document how to create Waffle application with JavaServer Pages (JSP).
January 26, 2006
The Glacial Methodology
The Waterfall Methodology is making a comeback in a big way. Hurry and register when you can ...
http://www.waterfall2006.com/
http://www.waterfall2006.com/
January 12, 2006
Mmmm Waffles...
It's been a while since I posted a blog, but I have been busy working on a new open source project. A new web framework for use in java/j2ee web applications.
Yes, I know there are already a plethora of java web frameworks, but Waffle (which is the name of the web framework) is different. Honest.
I wanted to work with a web framework that supports POJO based Actions, Dependency Injection, and it has no dependency on XML configuration files. Applications built on Waffle will be easier to develop and test with than other java web frameworks. Plus, it's buzz word compliant already fitting nicely with AJAX. :-)
Please have a look at the documentation and send me feedback on any suggestion you may have for improving the documentation or the framework itself.
Yes, I know there are already a plethora of java web frameworks, but Waffle (which is the name of the web framework) is different. Honest.
I wanted to work with a web framework that supports POJO based Actions, Dependency Injection, and it has no dependency on XML configuration files. Applications built on Waffle will be easier to develop and test with than other java web frameworks. Plus, it's buzz word compliant already fitting nicely with AJAX. :-)
Please have a look at the documentation and send me feedback on any suggestion you may have for improving the documentation or the framework itself.
August 31, 2005
Documentation for NanoContainer.NET
Been working on clearing up some of the issues with NanoContainer.NET and believe to have gotten to a point where hopefully we can consider going forward with a release. First thing that need to be done is documentation, so I have started to create documentation specific to the .NET implementation of NanoContainer. Take a look here.
August 16, 2005
Custom Attributes for NanoContainer.NET
I recently rolled onto the Beach after working on the same project for the past 7+ months. The project successfully utilize PicoContainer.NET for configuring both the client and server.
A colleague of mine, Jay Fields, and I have been discussing the use of .NET Attributes with pico/nano. I have for a while felt that the .NET implementation of pico and nano have really just been straight ports of the Java code while not really taking advantage of the features C# offers. One particular useful addition are Attributes.
So the past few days we have worked on a spike to take advantage of Attributes in the NanoContainer.NET. Utilizing Attributes in the code will allow us to define how an object is added to the container and will free us from having to create a separate script for loading the container. Here is an overview of the work we have done:
RegisterWithContainerAttribute - This is a class level attribute used by concrete classes that need to be registered with the container. The properties of this class are:
Now the CustomComponentAdapter doesn't really serve a purpose in this example, but I think it gets the point across. I think this addition to NanoContainer.NET is extremely useful and takes advantage of the language features. I think it also opens up the idea of utilizing similar functionality for Java 5.0 Annotations. Consistency between the two would be great.
A colleague of mine, Jay Fields, and I have been discussing the use of .NET Attributes with pico/nano. I have for a while felt that the .NET implementation of pico and nano have really just been straight ports of the Java code while not really taking advantage of the features C# offers. One particular useful addition are Attributes.
So the past few days we have worked on a spike to take advantage of Attributes in the NanoContainer.NET. Utilizing Attributes in the code will allow us to define how an object is added to the container and will free us from having to create a separate script for loading the container. Here is an overview of the work we have done:
Attribute:
RegisterWithContainerAttribute - This is a class level attribute used by concrete classes that need to be registered with the container. The properties of this class are:
- object key: which represents the key the component should be registered against
- ComponentAdapterType componentAdapterType: An enum that defines the type of component adapter (choices consist of Caching, NonCaching and Custom). Caching is the default.
- DependencyInjectionType dependencyInjectionType: An enum that defines the DI construct to follow (Constructor or Setter are the choices) as expected Constructor is the default type.
- Type componentAdapter: represents the concrete Type to use as the component adapter. This allows a concrete class to define a custom component adapter to use for itself.
Examples of use:
// constructor based with caching...
[RegisterWithContainer]
public class Foo : IFoo
{
private IBar bar;
public Foo(IBar bar)
{
this.bar = bar;
}
}
// setter based with caching
[RegisterWithContainer(DependencyInjection=DependencyInjectionType.Setter)]
public class Foo : IFoo
{
private IBar bar;
public IBar Bar
{
set {this.bar = value; }
}
}
// constructor based with non-caching...
[RegisterWithContainer(ComponentAdapterType.NonCaching)]
public class Foo : IFoo
{
private IBar bar;
public Foo(IBar bar)
{
this.bar = bar;
}
}
// setter based with non-caching...
[RegisterWithContainer(ComponentAdapterType.NonCaching,
DependencyInjection=DependencyInjectionType.Setter)]
public class Foo : IFoo
{
private IBar bar;
public IBar Bar
{
set {this.bar = value; }
}
}
// utilize a custom component adapter (caching and injection type are ignored for custom)
[RegisterWithContainer(ComponentAdapterType.Custom,
ComponentAdapter=typeof(CustomComponentAdapter))]
public class Foo : IFoo
{
private IBar bar;
public Foo(IBar bar)
{
this.bar = bar;
}
}
// example of the custom component adapter...
public class CustomComponentAdapter: CachingComponentAdapter
{
public CustomComponentAdapter(Type type)
: base(new ConstructorInjectionComponentAdapter(type))
{
}
}
Now the CustomComponentAdapter doesn't really serve a purpose in this example, but I think it gets the point across. I think this addition to NanoContainer.NET is extremely useful and takes advantage of the language features. I think it also opens up the idea of utilizing similar functionality for Java 5.0 Annotations. Consistency between the two would be great.
June 17, 2005
Dynamic Proxy missing from C#
There are many things about the C# language I really like and think Java would benefit from having. On the flip side of that several Java features are also sorely missed in C#. One in particular is dynamic proxy. The java implementation of dynamic proxy is java.lang.reflect.Proxy which is an extremely powerful feature. For those unfamiliar with dynamic proxy take a look at the JavaDoc to gain a deeper understanding of it.
For those who aren't interested in reading the JavaDoc here is a quick overview. Basically a dynamic proxy allows you to generate an instance of an Interface(s) at runtime without the need of a real implementation. So for example we have an Interface Foo
We can create an instance of Foo without having to have a class defined which actually implements Foo. In Java we can do this like so:
Now the actual power of this is handled in the implementation of the InvocationHandler. Here is a simple implementation of the InvocationHandler which traps method calls to the method hello().
While this is a very trivial example it does show how easy it is to create a proxy and how potentially powerful they are. Adding AOP type of functionality to method calls is simple to do, such as Security checks and the overused logging example.
Well back to my point. When working on the .NET port of PicoContainer I needed the ability to utilize a dynamic proxy for the ImplementationHidingComponentAdapter. This ComponentAdapter hides the implementation from the container. I figured I would easily be able to convert this logic to the C# port. To my surprise C# does not provide an out of the box simple implementation of dynamic proxy. They do provide the Emit API which will allow you to create your own proxy behavior for it. But creating a sufficient implementation of dynamic proxy from the Emit API is not a trivial task. Luckily the open source community has created an implementation of dynamic proxy for .NET called DynamicProxy.
Best to follow the documentation on the website itself or the related article on The Code Project. It's a good implementation and thoroughly tested. PicoContainer.NET utilizes it, as well as NHibernate. One caveat however is that at the moment it does not work with Mono, hopefully that will be fixed.
Mono error:
It would be great if Microsoft would add dynamic proxy support to the language but until then DynamicProxy seems like an nice tool.
For those who aren't interested in reading the JavaDoc here is a quick overview. Basically a dynamic proxy allows you to generate an instance of an Interface(s) at runtime without the need of a real implementation. So for example we have an Interface Foo
public interface Foo {
String hello();
}We can create an instance of Foo without having to have a class defined which actually implements Foo. In Java we can do this like so:
ClassLoader classLoader = Foo.class.getClassLoader();
Class[] interfaces = new Class[] { Foo.class }; // list of interfaces to support
InvocationHandler invocationHandler = ... // custom impl of InvocationHandler
Foo instance = (Foo) Proxy.newProxyInstance(classLoader, interfaces, invocationHandler);
Now the actual power of this is handled in the implementation of the InvocationHandler. Here is a simple implementation of the InvocationHandler which traps method calls to the method hello().
public class FooInvocationHandler implements InvocationHandler {
public Object invoke(Object proxy, Method method, Object[] args) {
if(method.getName().equals("hello")) {
System.out.println("The hello method was called!");
}
return "world";
}
}While this is a very trivial example it does show how easy it is to create a proxy and how potentially powerful they are. Adding AOP type of functionality to method calls is simple to do, such as Security checks and the overused logging example.
Well back to my point. When working on the .NET port of PicoContainer I needed the ability to utilize a dynamic proxy for the ImplementationHidingComponentAdapter. This ComponentAdapter hides the implementation from the container. I figured I would easily be able to convert this logic to the C# port. To my surprise C# does not provide an out of the box simple implementation of dynamic proxy. They do provide the Emit API which will allow you to create your own proxy behavior for it. But creating a sufficient implementation of dynamic proxy from the Emit API is not a trivial task. Luckily the open source community has created an implementation of dynamic proxy for .NET called DynamicProxy.
Best to follow the documentation on the website itself or the related article on The Code Project. It's a good implementation and thoroughly tested. PicoContainer.NET utilizes it, as well as NHibernate. One caveat however is that at the moment it does not work with Mono, hopefully that will be fixed.
Mono error:
** ERROR **: file class.c: line 2820 (mono_ldtoken): should not be reached
It would be great if Microsoft would add dynamic proxy support to the language but until then DynamicProxy seems like an nice tool.
June 16, 2005
JetBrains MPS: Meta Programming System
The folks over at JetBrains, makers of the excellent IntelliJ IDE, have released their latest project MPS or Meta Programming System. MPS appears to be a Language Workbench. The concept seems extremely interesting, and could potentially be a huge change with how systems are developed.
MPS can be downloaded through the EAP program JetBrains offers. MPS appears to have a dependency on the latest IntelliJ IDEA code named Irida, which too is available through JetBrains' EAP. The MPS is itself a plug-in for Irida IDE.
MPS can be downloaded through the EAP program JetBrains offers. MPS appears to have a dependency on the latest IntelliJ IDEA code named Irida, which too is available through JetBrains' EAP. The MPS is itself a plug-in for Irida IDE.
June 12, 2005
Languages , languages and more languages.
Earlier this year I started working with .NET, C# specifically. Since then I have also started to jump on the Ruby bandwagon. Most recently I've gone back in time and started re-learning C++. It's enjoyable spending time and getting into each language. I think it is valuable to have an understanding of what else is out there. Without a doubt I can see how expanding my knowledge with these languages will benefit me in general. I find that opening my mind to different concepts helps me with me think of things like: "How can I do something similar to this in Java?", or "What is the equivalent syntax for this in C#."
Next steps Ruby on Rails... or maybe I'll have to break out my old SmallTalk books.
Next steps Ruby on Rails... or maybe I'll have to break out my old SmallTalk books.
April 14, 2005
Project Structure for .NET applications
Over the last few months I have been working more and more with .NET (C# specifically). After working almost exclusively on Java projects for the last several years I have a bias for how a project should be laid out. However, I quickly realized that a Java projects structure does not translate easily to .NET. This seems specifically related to the nuances of Visual Studios.
I initially started investigating the different layouts for several popular .NET open source projects. Each project I looked at varied greatly in how it was laid out.
I was surprised to see that no common approach existed for .NET projects.
The following is a quick overview of how I have structured projects. I'll use PicoContainer as an example:
Java Project Structure
.NET Project Structure
The main difference is how package naming in Java does not translate easily to namespaces in .NET. The folders PicoContainer and PicoContainer.Tests are each separate Assemblies. PicoContainer.Tests of course contains a reference to PicoContainer. The differences are of course minor but from what I have seen there does not yet seem to be a standard project structure for .NET.
The advantage of the .NET layout is it works well with Visual Studios and does not require any tweaking of the project properties. Hacking the properties just makes things confusing and less intuitive.
I initially started investigating the different layouts for several popular .NET open source projects. Each project I looked at varied greatly in how it was laid out.
I was surprised to see that no common approach existed for .NET projects.
The following is a quick overview of how I have structured projects. I'll use PicoContainer as an example:
Java Project Structure
-- picocontainer
-- lib
-- src
-- java
-- org
-- picocontainer
-- defaults ...
-- test
-- org
-- picocontainer
-- defaults ...
.NET Project Structure
-- picocontainer
-- lib
-- src
-- PicoContainer
-- Defaults ...
-- PicoContainer.Tests
-- Defaults ...
The main difference is how package naming in Java does not translate easily to namespaces in .NET. The folders PicoContainer and PicoContainer.Tests are each separate Assemblies. PicoContainer.Tests of course contains a reference to PicoContainer. The differences are of course minor but from what I have seen there does not yet seem to be a standard project structure for .NET.
The advantage of the .NET layout is it works well with Visual Studios and does not require any tweaking of the project properties. Hacking the properties just makes things confusing and less intuitive.
Subscribe to:
Posts (Atom)