001: package org.sakaiproject.component.test.privacy;
002:
003: import junit.extensions.TestSetup;
004: import junit.framework.Test;
005: import junit.framework.TestSuite;
006: import java.util.*;
007:
008: import org.apache.commons.logging.Log;
009: import org.apache.commons.logging.LogFactory;
010:
011: import org.sakaiproject.api.privacy.PrivacyManager;
012: import org.sakaiproject.api.privacy.PrivacyRecord;
013: import org.sakaiproject.test.SakaiTestBase;
014:
015: public class PrivacyTest extends SakaiTestBase {
016: private static Log log = LogFactory.getLog(PrivacyTest.class);
017: private PrivacyManager privacyManager;
018:
019: public static Test suite() {
020: TestSetup setup = new TestSetup(
021: new TestSuite(PrivacyTest.class)) {
022: protected void setUp() throws Exception {
023: log.info("starting setup -- PrivacyTest");
024: oneTimeSetup();
025: log.info("finished setup -- PrivacyTest");
026: }
027:
028: protected void tearDown() throws Exception {
029: oneTimeTearDown();
030: }
031: };
032: return setup;
033: }
034:
035: public void setUp() throws Exception {
036: log.info("Setting up an AuthzIntegrationTest test");
037:
038: privacyManager = (PrivacyManager) getService(PrivacyManager.class
039: .getName());
040: }
041:
042: public void tearDown() throws Exception {
043: log.info("Tearing down an PrivacyTest test");
044:
045: privacyManager = null;
046: }
047:
048: public void testSetViewableState() throws Exception {
049: // privacyManager.setViewableState("main_page", "a", new Boolean(false), org.sakaiproject.api.privacy.PrivacyManager.USER_RECORD_TYPE);
050: // privacyManager.setViewableState("main_page", "a", new Boolean(true), org.sakaiproject.api.privacy.PrivacyManager.SYSTEM_RECORD_TYPE);
051: //
052: // privacyManager.setViewableState("main_page1", "a", new Boolean(false), org.sakaiproject.api.privacy.PrivacyManager.USER_RECORD_TYPE);
053: // privacyManager.setViewableState("main_page1", "a", new Boolean(true), org.sakaiproject.api.privacy.PrivacyManager.SYSTEM_RECORD_TYPE);
054: //
055: // privacyManager.setViewableState("main_page", "b", new Boolean(false), org.sakaiproject.api.privacy.PrivacyManager.USER_RECORD_TYPE);
056: // privacyManager.setViewableState("main_page", "b", new Boolean(true), org.sakaiproject.api.privacy.PrivacyManager.SYSTEM_RECORD_TYPE);
057: //
058: // privacyManager.setViewableState("main_page1", "b", new Boolean(true), org.sakaiproject.api.privacy.PrivacyManager.USER_RECORD_TYPE);
059: // privacyManager.setViewableState("main_page1", "b", new Boolean(true), org.sakaiproject.api.privacy.PrivacyManager.SYSTEM_RECORD_TYPE);
060: }
061:
062: public void testFindViewable() throws Exception {
063: Set inputSet = new TreeSet();
064: inputSet.add("a");
065: inputSet.add("b");
066: inputSet.add("c");
067: inputSet.add("d");
068: Set resultSet = privacyManager.findViewable("main_page",
069: inputSet);
070: Iterator iter = resultSet.iterator();
071: while (iter.hasNext()) {
072: String user = (String) iter.next();
073: log.info("Hidden users -- maing_page: " + user);
074: }
075: }
076:
077: public void testGetViewableState() throws Exception {
078: Set resultSet = privacyManager.getViewableState("main_page1",
079: new Boolean(true), PrivacyManager.SYSTEM_RECORD_TYPE);
080: Iterator iter = resultSet.iterator();
081: while (iter.hasNext()) {
082: String user = (String) iter.next();
083: log.info("PrivacyRecord -- main_page1:"
084: + PrivacyManager.SYSTEM_RECORD_TYPE + ":" + user);
085: }
086: }
087:
088: public void testGetViewableState2() throws Exception {
089: Map returnedMap = privacyManager.getViewableState("main_page",
090: PrivacyManager.USER_RECORD_TYPE);
091: Set keySet = returnedMap.keySet();
092: Iterator iter = keySet.iterator();
093: while (iter.hasNext()) {
094: String userId = (String) iter.next();
095: Boolean bl = (Boolean) returnedMap.get(userId);
096: log.info("testGetViewableState2 -- " + "main_page:"
097: + PrivacyManager.USER_RECORD_TYPE + ":" + userId
098: + ":" + bl.booleanValue());
099: }
100: }
101:
102: public void testSetViewableState2() throws Exception {
103: Map inputMap = new HashMap();
104: inputMap.put("a", new Boolean(false));
105: inputMap.put("b", new Boolean(true));
106: inputMap.put("c", new Boolean(true));
107: privacyManager.setViewableState("main_page", inputMap,
108: PrivacyManager.USER_RECORD_TYPE);
109: }
110:
111: public void testIsViewable() throws Exception {
112: log.info("Privacy Test -- testIsView:");
113: log.info(new Boolean(privacyManager
114: .isViewable("main_page", "a")).toString());
115: }
116: }
|