def testAddBeanWithNullResolver(self):
        container = BeanContainer(Person)

        # resolver that returns null as item id
        container.setBeanIdResolver(self.NullResolver())

        try:
            container.addBean(Person('John'))
            self.fail()
        except ValueError:
            pass  # should get exception

        try:
            container.addBeanAfter(None, Person('Jane'))
            self.fail()
        except ValueError:
            pass  # should get exception

        try:
            container.addBeanAt(0, Person('Jack'))
            self.fail()
        except ValueError:
            pass  # should get exception

        self.assertEquals(0, len(container))
    def testAddBeanWithoutResolver(self):
        container = BeanContainer(Person)

        try:
            container.addBean(Person('John'))
            self.fail()
        except self.IllegalStateException:
            pass  # should get exception

        try:
            container.addBeanAfter(None, Person('Jane'))
            self.fail()
        except self.IllegalStateException:
            pass  # should get exception

        try:
            container.addBeanAt(0, Person('Jack'))
            self.fail()
        except self.IllegalStateException:
            pass  # should get exception

        try:
            container.addAll( [Person('Jack')] )
            self.fail()
        except self.IllegalStateException:
            pass  # should get exception

        self.assertEquals(0, len(container))
    def testAddNestedContainerProperty(self):
        container = BeanContainer(NestedMethodPropertyTest.Person)
        container.setBeanIdProperty('name')

        container.addBean(NestedMethodPropertyTest.Person('John',
                NestedMethodPropertyTest.Address('Ruukinkatu 2-4', 20540)))

        self.assertTrue(container.addNestedContainerProperty('address.street'))
        self.assertEquals('Ruukinkatu 2-4',
                container.getContainerProperty('John',
                        'address.street').getValue())
    def testRemoveContainerProperty(self):
        container = BeanContainer(Person)
        container.setBeanIdResolver(self.PersonNameResolver())
        container.addBean(Person('John'))

        self.assertEquals('John',
                container.getContainerProperty('John', 'name').getValue())
        self.assertTrue(container.removeContainerProperty('name'))
        self.assertEquals(container.getContainerProperty('John', 'name'),
                None)

        self.assertNotEquals(container.getItem('John'), None)
        # property removed also from item
        self.assertEquals(container.getItem('John').getItemProperty('name'),
                None)
    def testAddNullBeansWithResolver(self):
        container = BeanContainer(Person)
        container.setBeanIdResolver(PersonNameResolver())

        self.assertEquals(container.addBean(None), None)
        self.assertEquals(container.addBeanAfter(None, None), None)
        self.assertEquals(container.addBeanAt(0, None), None)

        self.assertEquals(0, len(container))
    def testAddBeanWithPropertyResolver(self):
        container = BeanContainer(Person)
        container.setBeanIdProperty('name')

        self.assertNotEquals(container.addBean(Person('John')), None)
        self.assertNotEquals(container.addBeanAfter(None, Person('Jane')), None)
        self.assertNotEquals(container.addBeanAt(0, Person('Jack')), None)

        container.addAll( [Person('Jill'), Person('Joe')] )

        self.assertTrue(container.containsId('John'))
        self.assertTrue(container.containsId('Jane'))
        self.assertTrue(container.containsId('Jack'))
        self.assertTrue(container.containsId('Jill'))
        self.assertTrue(container.containsId('Joe'))
        self.assertEquals(3, container.indexOfId('Jill'))
        self.assertEquals(4, container.indexOfId('Joe'))
        self.assertEquals(5, len(container))