r4510 - trunk/test/edu/ucsb/nceas/metacattest

daigle at ecoinformatics.org daigle at ecoinformatics.org
Tue Nov 4 16:03:44 PST 2008


Author: daigle
Date: 2008-11-04 16:03:44 -0800 (Tue, 04 Nov 2008)
New Revision: 4510

Modified:
   trunk/test/edu/ucsb/nceas/metacattest/SitemapTest.java
Log:
Insert documents with different permissions and make sure only the publically readable ones get pulled into the sitemap file.

Modified: trunk/test/edu/ucsb/nceas/metacattest/SitemapTest.java
===================================================================
--- trunk/test/edu/ucsb/nceas/metacattest/SitemapTest.java	2008-11-05 00:02:07 UTC (rev 4509)
+++ trunk/test/edu/ucsb/nceas/metacattest/SitemapTest.java	2008-11-05 00:03:44 UTC (rev 4510)
@@ -29,10 +29,13 @@
 import java.io.FileNotFoundException;
 import java.io.FileReader;
 import java.io.IOException;
+import java.util.Vector;
 
 import edu.ucsb.nceas.MCTestCase;
 import edu.ucsb.nceas.metacat.DBConnectionPool;
 import edu.ucsb.nceas.metacat.Sitemap;
+import edu.ucsb.nceas.metacat.client.MetacatAuthException;
+import edu.ucsb.nceas.metacat.client.MetacatInaccessibleException;
 
 /**
  * Test the Sitemap class by generating the sitemaps in a separate directory.
@@ -50,35 +53,91 @@
         super.setUp();
 
         DBConnectionPool pool = DBConnectionPool.getInstance();
+        
+		metacatConnectionNeeded = true;
+		super.setUp();
     }
 
     /**
      * Test the static generateSitemaps() method.
      */
-    public void testGenerateSitemaps() {
-        File directory = new File(directoryName);
-        directory.mkdirs();
-        String urlRoot = "http://foo.example.com/ctx/metacat";
-        String skin = "testskin";
-        Sitemap smap = new Sitemap(directory, urlRoot, skin);
-        smap.generateSitemaps();
-        File sitemap1 = new File(directory, "metacat1.xml");
-        assertTrue(sitemap1.exists() && sitemap1.isFile());
-        try {
-            FileReader r = new FileReader(sitemap1);
-            BufferedReader br = new BufferedReader(r);
-            char[] buf = new char[1024];
-            br.read(buf, 0, 1024);
-            br.close();
-            String doc = new String(buf);
-            assertTrue(doc.indexOf("<?xml") >= 0);
-            assertTrue(doc.indexOf("<urlset") >= 0);
-            assertTrue(doc.indexOf("<url>") >= 0);
-            assertTrue(doc.indexOf("http:") >= 0);
-        } catch (FileNotFoundException e) {
-            fail("Failed to read the sitemap file." + e.getMessage());
-        } catch (IOException ioe) {
-            fail("Failed while reading sitemap file." + ioe.getMessage());
-        }
+    public void testGenerateSitemaps() {	
+    	try {
+			debug("\nRunning: testGenerateSitemaps()");
+
+			// login
+			debug("logging in as: username=" + username + " password=" + password);
+			m.login(username, password);
+
+			// insert 2.0.1 document
+			String docid1 = generateDocumentId();
+			debug("inserting docid: " + docid1 + ".1 which has no access section");
+			testdocument = getTestEmlDoc("Doc with no access section", EML2_0_1, null,
+					null, null, null, null, null, null, null, null);
+			insertDocumentId(docid1 + ".1", testdocument, SUCCESS, false);
+			readDocumentIdWhichEqualsDoc(docid1, testdocument, SUCCESS, false);
+
+			String docid2 = generateDocumentId();
+			debug("inserting docid: " + docid2 + ".1 which has public read/write section");
+			Vector<String> accessRules1 = new Vector<String>();
+			String accessRule1 = generateOneAccessRule("public", true, true, true, false, false);
+			accessRules1.add(accessRule1);
+			String accessBlock = getAccessBlock(accessRules1, ALLOWFIRST);
+			testdocument = getTestEmlDoc(
+					"Doc with public read and write", EML2_0_1,
+					null, null, null, null, accessBlock, null, null, null, null);
+			insertDocumentId(docid2 + ".1", testdocument, SUCCESS, false);
+			
+			String docid3 = generateDocumentId();
+			debug("inserting docid: " + docid3 + ".1 which has which has " + username + " read/write section");
+			Vector<String> accessRules2 = new Vector<String>();
+			String accessRule2 = generateOneAccessRule(username, true, true, true, false, false);
+			accessRules2.add(accessRule2);
+			String accessBlock2 = getAccessBlock(accessRules2, ALLOWFIRST);
+			testdocument = getTestEmlDoc(
+					"Doc with public read and write", EML2_0_1,
+					null, null, null, null, accessBlock2, null, null, null, null);
+			insertDocumentId(docid3 + ".1", testdocument, SUCCESS, false);
+			
+			debug("logging out");
+			m.logout();
+
+			File directory = new File(directoryName);
+			directory.mkdirs();
+			String urlRoot = "http://foo.example.com/ctx/metacat";
+			String skin = "testskin";
+			Sitemap smap = new Sitemap(directory, urlRoot, skin);
+			smap.generateSitemaps();
+			File sitemap1 = new File(directory, "metacat1.xml");
+			assertTrue(sitemap1.exists() && sitemap1.isFile());
+
+			FileReader r = new FileReader(sitemap1);
+			BufferedReader br = new BufferedReader(r);
+			char[] buf = new char[1024];
+			br.read(buf, 0, 1024);
+			br.close();
+			String doc = new String(buf);
+			//debug("**** sitemap doc *** \n");
+			//debug(doc);
+			assertTrue(doc.indexOf("<?xml") >= 0);
+			assertTrue(doc.indexOf("<urlset") >= 0);
+			assertTrue(doc.indexOf("<url>") >= 0);
+			assertTrue(doc.indexOf("http:") >= 0);
+			
+			// only docid 2 should show up in the sitemap.
+			assertTrue(doc.indexOf(docid1) == -1);
+			assertTrue(doc.indexOf(docid2) >= 0);
+			assertTrue(doc.indexOf(docid3) == -1);
+		} catch (FileNotFoundException e) {
+			fail("Failed to read the sitemap file." + e.getMessage());
+		} catch (IOException ioe) {
+			fail("Failed while reading sitemap file." + ioe.getMessage());
+		} catch (MetacatAuthException mae) {
+			fail("Authorization failed:\n" + mae.getMessage());
+		} catch (MetacatInaccessibleException mie) {
+			fail("Metacat Inaccessible:\n" + mie.getMessage());
+		} catch (Exception e) {
+			fail("General exception:\n" + e.getMessage());
+		}
     }
 }



More information about the Metacat-cvs mailing list