Index: quintagroup.canonicalpath/trunk/quintagroup/canonicalpath/tests.py
===================================================================
--- quintagroup.canonicalpath/trunk/quintagroup/canonicalpath/tests.py	(revision 1708)
+++ quintagroup.canonicalpath/trunk/quintagroup/canonicalpath/tests.py	(revision 1922)
@@ -4,4 +4,5 @@
 from zope.component import testing
 from zope.component import queryAdapter, queryMultiAdapter
+from zope.schema.interfaces import InvalidValue
 from plone.indexer.interfaces import IIndexableObject
 from Testing import ZopeTestCase as ztc
@@ -16,4 +17,5 @@
 
 from quintagroup.canonicalpath.interfaces import ICanonicalPath
+from quintagroup.canonicalpath.adapters import PROPERTY
 
 class TestCase(ptc.PloneTestCase):
@@ -28,47 +30,104 @@
 ptc.setupPloneSite()
 
-class TestAdapter(TestCase):
+class TestIndexerRegistration(TestCase):
 
     def afterSetUp(self):
         self.loginAsPortalOwner()
+        self.catalog = getToolByName(self.portal, 'portal_catalog')
         self.my_doc = makeContent(self.portal, portal_type='Document', id='my_doc')
-        self.purl = getToolByName(self.portal, 'portal_url')
-        self.catalog = getToolByName(self.portal, 'portal_catalog')
         self.logout()
 
-    def testAdapter4Portal(self):
+    def testForPortal(self):
+        wrapper = queryMultiAdapter((self.portal, self.catalog), IIndexableObject)
+        self.assertFalse(wrapper is None, "No indexer registered for portal object")
+
+    def testForAT(self):
+        wrapper = queryMultiAdapter((self.my_doc, self.catalog), IIndexableObject)
+        self.assertFalse(wrapper is None, "No indexer registered for document object")
+        
+        
+class TestDefaultAdapter(TestCase):
+
+
+    def afterSetUp(self):
+        self.loginAsPortalOwner()
+        self.purl = getToolByName(self.portal, 'portal_url')
+        self.my_doc = makeContent(self.portal, portal_type='Document', id='my_doc')
+        self.logout()
+
+        self.mydoc_cp = '/'+'/'.join(self.purl.getRelativeContentPath(self.my_doc))
+        self.portal_cp = '/'+'/'.join(self.purl.getRelativeContentPath(self.portal))
+
+    def testRegistration4Portal(self):
         cpadapter = queryAdapter(self.portal, ICanonicalPath)
         self.assertFalse(cpadapter is None,
             "Can't get canonical path adapter for the plone site object")
 
-
-        portal_cp = '/'+'/'.join(self.purl.getRelativeContentPath(self.portal))
-        adcp = cpadapter.canonical_path()
-        self.assertTrue(adcp == portal_cp, "Canonical path adapter return '%s' "\
-            "for portal, must be: '%s'" % (adcp, portal_cp) )
-
-
-    def testAdapter4AT(self):
+    def testRegistration4AT(self):
         cpadapter = queryAdapter(self.my_doc, ICanonicalPath)
         self.assertFalse(cpadapter is None,
             "Can't get canonical path adapter for the Document object")
+        
 
-        mydoc_cp = '/'+'/'.join(self.purl.getRelativeContentPath(self.my_doc))
-        adcp = cpadapter.canonical_path()
-        self.assertTrue(adcp == mydoc_cp, "Canonical path adapter return '%s' "\
-            "for document, must be: '%s'" % (adcp, mydoc_cp) )
+    def testGetDefault4Portal(self):
+        cpadapter = queryAdapter(self.portal, ICanonicalPath)
+        self.assertTrue(cpadapter.canonical_path == self.portal_cp,
+            "Canonical path adapter return '%s' for portal, must be: '%s'" % (
+            cpadapter.canonical_path, self.portal_cp) )
 
 
-    def testIndexerRegistration(self):
-        wrapper = queryMultiAdapter((self.portal, self.catalog), IIndexableObject)
-        self.assertFalse(wrapper is None, "No indexer registered for portal object")
+    def testGetDefault4AT(self):
+        cpadapter = queryAdapter(self.my_doc, ICanonicalPath)
+        self.assertTrue(cpadapter.canonical_path == self.mydoc_cp,
+            "Canonical path adapter return '%s' for document, must be: '%s'" % (
+            cpadapter.canonical_path, self.mydoc_cp) )
 
-        wrapper = queryMultiAdapter((self.my_doc, self.catalog), IIndexableObject)
-        self.assertFalse(wrapper is None, "No indexer registered for document object")
-        
-        
+
+    def testSet4Portal(self):
+        cpadapter = queryAdapter(self.portal, ICanonicalPath)
+        newcp = self.portal_cp + '/new_portal_canonical'
+
+        cpadapter.canonical_path = newcp
+        prop = self.portal.getProperty(PROPERTY, None)
+        self.assertTrue(prop == newcp,
+            "Canonical path adapter setter NOT SET new '%s' value to '%s' " \
+            "propery for the portal" % (newcp, PROPERTY) )
+
+        self.assertTrue(cpadapter.canonical_path == newcp,
+            "Canonical path adapter GET '%s' canonical_path, for portal, " \
+            "must be: '%s'" % (cpadapter.canonical_path, newcp) )
+
+
+    def testSet4AT(self):
+        cpadapter = queryAdapter(self.my_doc, ICanonicalPath)
+        newcp = self.mydoc_cp + '/new_mydoc_canonical'
+
+        cpadapter.canonical_path = newcp
+        prop = self.my_doc.getProperty(PROPERTY, None)
+        self.assertTrue(prop == newcp,
+            "Canonical path adapter setter NOT SET new '%s' value to '%s' " \
+            "propery for the Document" % (newcp, PROPERTY) )
+
+        self.assertTrue(cpadapter.canonical_path == newcp,
+            "Canonical path adapter GET '%s' canonical_path, for Document, " \
+            "must be: '%s'" % (cpadapter.canonical_path, newcp) )
+
+
+    def testValidation(self):
+        cpadapter = queryAdapter(self.my_doc, ICanonicalPath)
+        for wrong in ['new\nline','s p a c e','with\ttabs']:
+            try:
+                cpadapter.canonical_path = wrong
+            except InvalidValue:
+                continue
+            else:
+                raise self.failureException, "InvalidValue not raised when " \
+                      "wrong value set"
+
+
 def test_suite():
     return unittest.TestSuite([
-        unittest.makeSuite(TestAdapter),
+        unittest.makeSuite(TestIndexerRegistration),
+        unittest.makeSuite(TestDefaultAdapter),
         ])
 
