001: /**********************************************************************************
002: * $URL: $
003: * $Id: $
004: ***********************************************************************************
005: *
006: * Copyright (c) 2004, 2005, 2006 The Sakai Foundation.
007: *
008: * Licensed under the Educational Community License, Version 1.0 (the"License");
009: * you may not use this file except in compliance with the License.
010: * You may obtain a copy of the License at
011: *
012: * http://www.opensource.org/licenses/ecl1.php
013: *
014: * Unless required by applicable law or agreed to in writing, software
015: * distributed under the License is distributed on an "AS IS" BASIS,
016: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: * See the License for the specific language governing permissions and
018: * limitations under the License.
019: *
020: *
021: **********************************************************************************/package org.sakaiproject.tool.assessment.test.integration.helper.ifc;
022:
023: import junit.framework.*;
024: import org.sakaiproject.tool.assessment.integration.helper.ifc.*;
025: import java.util.*;
026: import org.sakaiproject.tool.assessment.data.dao.authz.*;
027:
028: public class TestAuthzHelper extends TestCase {
029: private AuthzHelper authzHelper = null;
030: boolean integrated;
031:
032: public TestAuthzHelper(AuthzHelper helper, boolean integrated) {
033: this .authzHelper = helper;
034: this .integrated = integrated;
035: assertNotNull(authzHelper);
036: }
037:
038: protected void setUp() throws Exception {
039: super .setUp();
040: /**@todo verify the constructors*/
041: authzHelper = null;
042: }
043:
044: protected void tearDown() throws Exception {
045: authzHelper = null;
046: super .tearDown();
047: }
048:
049: // I don't like this, this method seems to want to return null on find fail
050: public void testGetAuthorizationByAgentAndFunction() {
051: String agentId = "bogus";//a bogus agent
052: String functionId = "bogus";//a bogus function, change if used
053:
054: List actualReturn = null;
055: try {
056: actualReturn = authzHelper
057: .getAuthorizationByAgentAndFunction(agentId,
058: functionId);
059: } catch (Exception ex) {
060: log.warn(ex.getMessage());
061: }
062: assertNotNull(actualReturn);
063: assertEquals(actualReturn.size(), 0);
064: }
065:
066: public void testCheckAuthorization() {
067: String agentId = "esmiley";
068: String functionId = "update";
069: String qualifierId = "wombats";
070: boolean actualReturn = true;
071: boolean unimplemented = false;
072: try {
073: actualReturn = authzHelper.checkAuthorization(agentId,
074: functionId, qualifierId);
075: } catch (java.lang.UnsupportedOperationException ex) {
076: unimplemented = true;
077: }
078:
079: if (isStandalone()) {
080: assertTrue(unimplemented);
081: }
082: if (this .isIntegrated()) {
083: assertFalse(actualReturn);
084: }
085: }
086:
087: public void testGetAuthorizationByFunctionAndQualifier() {
088: String qualifierId = "a bogus q string";
089: String functionId = "a bogus function";
090:
091: List actualReturn = null;
092: try {
093: actualReturn = authzHelper
094: .getAuthorizationByFunctionAndQualifier(functionId,
095: qualifierId);
096: } catch (Exception ex) {
097: log.warn(ex.getMessage());
098: }
099:
100: assertNotNull(actualReturn);
101: assertEquals(actualReturn.size(), 0);
102: }
103:
104: public void testCheckMembership() {
105: String siteId = "a bogus nonexistent site";
106: boolean actualReturn = authzHelper.checkMembership(siteId);
107:
108: if (isStandalone()) {
109: assertTrue(actualReturn);
110: }
111: if (this .isIntegrated()) {
112: this .assertFalse(actualReturn);
113: }
114: }
115:
116: public void testGetAssessmentsByAgentAndFunction() {
117: String agentId = "esmiley";
118: String functionId = "update";
119: ArrayList actualReturn = null;
120: boolean unimplemented = false;
121: try {
122: actualReturn = authzHelper.getAssessments(agentId,
123: functionId);
124: } catch (java.lang.UnsupportedOperationException ex) {
125: unimplemented = true;
126: }
127:
128: if (isStandalone()) {
129: assertTrue(unimplemented);
130: }
131: if (this .isIntegrated()) {
132: assertNotNull(actualReturn);
133: assertEquals("return value", 0, actualReturn.size());
134: }
135: }
136:
137: public void testRemoveAuthorizationByQualifier() {
138: boolean success = false;
139: try {
140: String qualifierId = "this is a non-existent bogus qualifier";
141: authzHelper.removeAuthorizationByQualifier(qualifierId);
142: success = true;
143: } catch (Exception ex) {
144: log.warn(ex.getMessage());
145: }
146: assertTrue(success);
147: }
148:
149: public void testCreateAuthorization() {
150: String agentId = null;
151: String functionId = null;
152: String qualifierId = null;
153: AuthorizationData expectedReturn = null;
154: AuthorizationData actualReturn = null;
155: boolean createdWithNulls = false; // should NEVER happen, in stand. OR int.
156: try {
157: actualReturn = authzHelper.createAuthorization(agentId,
158: functionId, qualifierId);
159: createdWithNulls = true; //UH-OH
160: } catch (Exception ex) {
161: log.warn(ex.getMessage());
162: }
163: assertEquals("return value", expectedReturn, actualReturn);
164: assertFalse(createdWithNulls);
165: }
166:
167: public void testGetAssessments() {
168: ArrayList expectedReturn = null;
169: String agentId = "esmiley";
170: String functionId = "update";
171: ArrayList actualReturn = null;
172: boolean unimplemented = false;
173: try {
174: actualReturn = authzHelper.getAssessments(agentId,
175: functionId);
176: } catch (java.lang.UnsupportedOperationException ex) {
177: unimplemented = true;
178: }
179:
180: if (isStandalone()) {
181: assertTrue(unimplemented);
182: }
183: if (this .isIntegrated()) {
184: assertNotNull(actualReturn);
185: assertEquals("return value", 0, actualReturn.size());
186: }
187: }
188:
189: public void testIsAuthorized() {
190: String agentId = "esmiley";
191: String functionId = "update";
192: String qualifierId = "wombats";
193: boolean actualReturn = authzHelper.isAuthorized(agentId,
194: functionId, qualifierId);
195: if (isStandalone()) {
196: assertTrue(actualReturn);
197: }
198: if (this .isIntegrated()) {
199: assertFalse(actualReturn);
200: }
201: }
202:
203: public void testGetAuthorizationToViewAssessments() {
204: HashMap expectedReturn = null;
205: String agentId = "a bogus agent string";
206:
207: HashMap actualReturn = authzHelper
208: .getAuthorizationToViewAssessments(agentId);
209:
210: assertNotNull(actualReturn);
211: assertEquals("return value", 0, actualReturn.size());
212: // assertNotNull(actualReturn);
213: //assertEquals(actualReturn.size(), 0);
214:
215: }
216:
217: public boolean isIntegrated() {
218: return integrated;
219: }
220:
221: public boolean isStandalone() {
222: return !integrated;
223: }
224:
225: }
|