class countWorkitemsTestCase(unittest.TestCase):

    def setUp(self):
        # Create an OpenFlow folder
        self.of = CMFOpenflowTool('of')

        # Create some Process Definition
        for id in ['first','second','third']:
            self.of.addProcess(id=id, BeginEnd=1)
            self.pd = getattr(self.of, id)
            self.pd.addTransition(id=id, From='Begin', To='End')
            self.pd['Begin'].edit(kind='Standard')
            # Routing: 6 workitems
            # instance with workitem inactive and unassigned
            pid = self.of.addInstance(id, 'test1', 'testComment', 'TestTitle', 1)
            # instance with workitem inactive and assigned
            pid = self.of.addInstance(id, 'test2', 'testComment', 'TestTitle', 1)
            pid = self.of.assignWorkitem(pid,'0','testUser')
            # instance with workitem active
            pid = self.of.addInstance(id, 'test3', 'testComment', 'TestTitle', 1)
            self.of.activateWorkitem(pid,'0','testUser')
            # instance with workitem completed
            pid=self.of.addInstance(id, 'test4', 'testComment', 'TestTitle', 1)
            self.of.activateWorkitem(pid,'0','testUser')
            self.of.completeWorkitem(pid,'0')
            # instance with 2 workitems completed
            pid=self.of.addInstance(id, 'test5', 'testComment', 'TestTitle', 1)
            self.of.activateWorkitem(pid,'0','testUser')
            self.of.completeWorkitem(pid,'0')
            self.of.forwardWorkitem(pid,'0')

    def checkCountWorkitems(self):
        """ Check results of countWorkitems"""
        assert self.of.countWorkitems()=={'to do':'6', 'to assign':'3', 'completed':'9'},'Result error for process'
        assert self.of.countWorkitems('first')=={'to do':'2', 'to assign':'1', 'completed':'3'},'Result error for process'
        assert self.of.countWorkitems('first','Begin')=={'to do':'2', 'to assign':'1', 'completed':'2'},'Result error for process and activity'
        assert self.of.countWorkitems('first','Begin','testUser')=={'to do':'2', 'to assign':'1', 'completed':'2'},'Result error for process, activity and user'