def testCollectionConstructors(self):
        warn('deprecated', DeprecationWarning)

        classNames = list()
        classNames.append(ClassName('a.b.c.Def', 1))
        classNames.append(ClassName('a.b.c.Fed', 2))
        classNames.append(ClassName('b.c.d.Def', 3))

        # note that this constructor is problematic, users should use the
        # version that
        # takes the bean class as a parameter
        container = BeanItemContainer(classNames)

        self.assertEquals(3, len(container))
        self.assertEquals(classNames[0], container.firstItemId())
        self.assertEquals(classNames[1], container.getIdByIndex(1))
        self.assertEquals(classNames[2], container.lastItemId())

        container2 = BeanItemContainer(ClassName, classNames)

        self.assertEquals(3, len(container2))
        self.assertEquals(classNames[0], container2.firstItemId())
        self.assertEquals(classNames[1], container2.getIdByIndex(1))
        self.assertEquals(classNames[2], container2.lastItemId())
    def testContainerOrdered(self):
        container = BeanItemContainer(str)

        idd = 'test1'

        item = container.addBean(idd)
        self.assertNotEquals(item, None)

        self.assertEquals(idd, container.firstItemId())
        self.assertEquals(idd, container.lastItemId())

        # isFirstId
        self.assertTrue(container.isFirstId(idd))
        self.assertTrue(container.isFirstId(container.firstItemId()))

        # isLastId
        self.assertTrue(container.isLastId(idd))
        self.assertTrue(container.isLastId(container.lastItemId()))

        # Add a new item before the first
        # addItemAfter
        newFirstId = 'newFirst'
        item = container.addItemAfter(None, newFirstId)
        self.assertNotEquals(item, None)
        self.assertNotEquals(container.getItem(newFirstId), None)

        # isFirstId
        self.assertTrue(container.isFirstId(newFirstId))
        self.assertTrue(container.isFirstId(container.firstItemId()))

        # isLastId
        self.assertTrue(container.isLastId(idd))
        self.assertTrue(container.isLastId(container.lastItemId()))

        # nextItemId
        self.assertEquals(idd, container.nextItemId(newFirstId))
        self.assertEquals(container.nextItemId(idd), None)
        self.assertEquals(container.nextItemId('not-in-container'), None)

        # prevItemId
        self.assertEquals(newFirstId, container.prevItemId(idd))
        self.assertEquals(container.prevItemId(newFirstId), None)
        self.assertEquals(container.prevItemId('not-in-container'), None)

        # addItemAfter(Object)
        newSecondItemId = 'newSecond'
        item = container.addItemAfter(newFirstId, newSecondItemId)

        # order is now: newFirstId, newSecondItemId, idd
        self.assertNotEquals(item, None)
        self.assertNotEquals(container.getItem(newSecondItemId), None)
        self.assertEquals(idd, container.nextItemId(newSecondItemId))
        self.assertEquals(newFirstId, container.prevItemId(newSecondItemId))

        # addItemAfter(Object,Object)
        fourthId = 'idd of the fourth item'
        fourth = container.addItemAfter(newFirstId, fourthId)

        # order is now: newFirstId, fourthId, newSecondItemId, idd
        self.assertNotEquals(fourth, None)
        self.assertEquals(fourth, container.getItem(fourthId))
        self.assertEquals(newSecondItemId, container.nextItemId(fourthId))
        self.assertEquals(newFirstId, container.prevItemId(fourthId))

        # addItemAfter(Object,Object)
        fifthId = 'fifth'
        fifth = container.addItemAfter(None, fifthId)
        # order is now: fifthId, newFirstId, fourthId, newSecondItemId, idd
        self.assertNotEquals(fifth, None)
        self.assertEquals(fifth, container.getItem(fifthId))
        self.assertEquals(newFirstId, container.nextItemId(fifthId))
        self.assertEquals(container.prevItemId(fifthId), None)
    def testAddRemoveWhileFiltering(self):
        container = BeanItemContainer(Person)

        john = Person('John')
        jane = Person('Jane')
        matthew = Person('Matthew')

        jack = Person('Jack')
        michael = Person('Michael')
        william = Person('William')
        julia = Person('Julia')
        george = Person('George')
        mark = Person('Mark')

        container.addBean(john)
        container.addBean(jane)
        container.addBean(matthew)

        self.assertEquals(3, len(container))
        # john, jane, matthew

        container.addContainerFilter('name', 'j', True, True)

        self.assertEquals(2, len(container))
        # john, jane, (matthew)

        # add a bean that passes the filter
        container.addBean(jack)
        self.assertEquals(3, len(container))
        self.assertEquals(jack, container.lastItemId())
        # john, jane, (matthew), jack

        # add beans that do not pass the filter
        container.addBean(michael)
        # john, jane, (matthew), jack, (michael)
        container.addItemAfter(None, william)
        # (william), john, jane, (matthew), jack, (michael)

        # add after an item that is shown
        container.addItemAfter(john, george)
        # (william), john, (george), jane, (matthew), jack, (michael)
        self.assertEquals(3, len(container))
        self.assertEquals(john, container.firstItemId())

        # add after an item that is not shown does nothing
        container.addItemAfter(william, julia)
        # (william), john, (george), jane, (matthew), jack, (michael)
        self.assertEquals(3, len(container))
        self.assertEquals(john, container.firstItemId())

        container.addItemAt(1, julia)
        # (william), john, julia, (george), jane, (matthew), jack, (michael)
        container.addItemAt(2, mark)
        # (william), john, julia, (mark), (george), jane, (matthew), jack,
        # (michael)

        container.removeItem(matthew)
        # (william), john, julia, (mark), (george), jane, jack, (michael)

        self.assertEquals(4, len(container))
        self.assertEquals(jack, container.lastItemId())

        container.removeContainerFilters('name')

        self.assertEquals(8, len(container))
        self.assertEquals(william, container.firstItemId())
        self.assertEquals(john, container.nextItemId(william))
        self.assertEquals(julia, container.nextItemId(john))
        self.assertEquals(mark, container.nextItemId(julia))
        self.assertEquals(george, container.nextItemId(mark))
        self.assertEquals(jane, container.nextItemId(george))
        self.assertEquals(jack, container.nextItemId(jane))
        self.assertEquals(michael, container.lastItemId())