Index: main/waeup.sirp/trunk/src/waeup/sirp/applications/tests/test_root.py
===================================================================
--- main/waeup.sirp/trunk/src/waeup/sirp/applications/tests/test_root.py	(revision 5658)
+++ main/waeup.sirp/trunk/src/waeup/sirp/applications/tests/test_root.py	(revision 5659)
@@ -23,8 +23,15 @@
 Test applications root.
 """
+import logging
 import unittest
+from StringIO import StringIO
 from zope.interface.verify import verifyClass, verifyObject
 from waeup.sirp.applications import interfaces
-from waeup.sirp.applications.root import ApplicationsRoot
+from waeup.sirp.applications.root import (
+    ApplicationsRoot, ApplicationsPlugin,
+    )
+
+class FakeSite(dict):
+    pass
 
 class ApplicationsRootTestCase(unittest.TestCase):
@@ -42,11 +49,103 @@
         return
 
+class ApplicationsRootPluginTestCase(unittest.TestCase):
+    def create_logger(self):
+        # create a logger suitable for local tests.
+        test_logger = logging.getLogger('waeup.sirp.applications.testlogger')
+        log = StringIO()
+        handler = logging.StreamHandler(log)
+        handler.setLevel(logging.DEBUG)
+        test_logger.addHandler(handler)
+        test_logger.setLevel(logging.DEBUG)
+        self.logger = test_logger
+        self.log = log
+        self.handler = handler
+        return self.logger
+
+    def remove_logger(self):
+        del self.handler
+        del self.logger
+        del self.log
+        pass
+
+    def get_log(self):
+        self.log.seek(0)
+        return self.log.read()
+
+    def setUp(self):
+        self.create_logger()
+        return
+
+    def tearDown(self):
+        self.remove_logger()
+        return
+
+    # Real tests start here...
+    def test_pluginsetup(self):
+        # Make sure we can add ApplicationsRoot to sites.
+        site = FakeSite()
+        plugin = ApplicationsPlugin()
+        plugin.setup(site, 'blah', self.logger)
+        self.assertTrue('applications' in site.keys())
+        log = self.get_log()
+        self.assertTrue('Installed applications root.' in log)
+        return
+
+    def test_update_new(self):
+        # Run update on a site without applications root.
+        site = FakeSite()
+        plugin = ApplicationsPlugin()
+        plugin.update(site, 'blah', self.logger)
+        self.assertTrue('applications' in site.keys())
+        log = self.get_log()
+        self.assertTrue('Updating site at Unnamed Site' in log)
+        self.assertTrue('Installed applications root.' in log)
+        return
+
+    def test_update_outdated(self):
+        # Run update on a site with outdated applications root.
+        site = FakeSite()
+        root = object() # # This is not a proper applications root
+        site['applications'] = root
+        plugin = ApplicationsPlugin()
+        plugin.update(site, 'blah', self.logger)
+        self.assertTrue(site['applications'] is not root)
+        self.assertTrue(isinstance(site['applications'], ApplicationsRoot))
+        log = self.get_log()
+        self.assertTrue('Outdated applications folder detected' in log)
+        self.assertTrue('Updating site at Unnamed Site' in log)
+        self.assertTrue('Installed applications root.' in log)
+        return
+
+    def test_update_uptodate(self):
+        # Run update on a site with proper applications root.
+        site = FakeSite()
+        root = ApplicationsRoot()
+        site['applications'] = root
+        plugin = ApplicationsPlugin()
+        plugin.update(site, 'blah', self.logger)
+        self.assertTrue(site['applications'] is root)
+        log = self.get_log()
+        self.assertTrue('Updating site at Unnamed Site' in log)
+        self.assertTrue('Nothing to do' in log)
+        return
+
+    def test_update_log(self):
+        # Check that sitename is used in log messages on updates.
+        site = FakeSite()
+        site.__name__ = 'my_site'
+        plugin = ApplicationsPlugin()
+        plugin.update(site, 'blah', self.logger)
+        log = self.get_log()
+        self.assertTrue('Updating site at my_site.' in log)
+        return
+        
 def suite():
     suite = unittest.TestSuite()
-    suite.addTests(
-        unittest.TestLoader().loadTestsFromTestCase(
+    for testcase in [
             ApplicationsRootTestCase,
-            )
-        )
+            ApplicationsRootPluginTestCase,
+            ]:
+        suite.addTests(unittest.TestLoader().loadTestsFromTestCase(testcase))
     return suite
 
