Skip to content

Instantly share code, notes, and snippets.

@uarun
Created November 25, 2011 22:48
Show Gist options
  • Save uarun/1394600 to your computer and use it in GitHub Desktop.
Save uarun/1394600 to your computer and use it in GitHub Desktop.
Creating collections in BeanBuilder
import static org.junit.Assert.*;
import org.springframework.beans.factory.config.ListFactoryBean;
import grails.spring.BeanBuilder;
import grails.test.GrailsUnitTestCase;
class BeanBuilderTests extends GrailsUnitTestCase {
void testListCreation() {
def bb = new BeanBuilder()
bb.beans {
myList(ListFactoryBean) {
sourceList = [String.class, Integer.class]
}
}
def appCtx = bb.createApplicationContext()
def mlist = appCtx.getBean("myList");
assertEquals 2, mlist.size()
}
void testListCreationUsingNamespace() {
def bb = new BeanBuilder()
bb.beans {
xmlns util:"http://www.springframework.org/schema/util"
util.list(id: "myList", "list-class": LinkedList.name) {
value Integer.class
value String.class
}
def values = [ Integer.class, String.class, Integer.class ]
util.set(id: "mySet", "set-class": TreeSet.name) {
values.each {
value it
}
}
anotherList(ArrayList, ref('mySet'))
}
def appCtx = bb.createApplicationContext()
def mlist = appCtx.getBean("myList");
def mset = appCtx.getBean("mySet");
def alist = appCtx.getBean("anotherList");
assertEquals 2, mlist.size()
assertEquals 2, mset.size()
assertEquals 2, alist.size()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment