001: /*
002: * Copyright 2005-2007 The Kuali Foundation.
003: *
004: * Licensed under the Educational Community License, Version 1.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.opensource.org/licenses/ecl1.php
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.kuali.core.service.impl;
017:
018: import static org.kuali.test.fixtures.UserNameFixture.KHUNTLEY;
019:
020: import java.util.LinkedHashMap;
021:
022: import org.kuali.core.document.Document;
023: import org.kuali.core.document.DocumentBase;
024: import org.kuali.core.document.authorization.DocumentAuthorizer;
025: import org.kuali.core.service.DocumentAuthorizationService;
026: import org.kuali.core.service.DocumentService;
027: import org.kuali.kfs.context.KualiTestBase;
028: import org.kuali.kfs.context.SpringContext;
029: import org.kuali.module.financial.document.InternalBillingDocument;
030: import org.kuali.test.ConfigureContext;
031:
032: @ConfigureContext(session=KHUNTLEY)
033: public class DocumentAuthorizationServiceImplTest extends KualiTestBase {
034:
035: private static final String NULL_DOCTYPE = null;
036: private static final String BLANK_DOCTYPE = " ";
037: private static final String UNKNOWN_DOCTYPE = "foo";
038: private static final String KNOWN_DOCTYPE = "InternalBillingDocument";
039:
040: private static final Document NULL_DOCUMENT = null;
041:
042: public final void testGetDocumentAuthorizer1_nullDocumentTypeName() {
043: boolean failedAsExpected = false;
044:
045: try {
046: SpringContext.getBean(DocumentAuthorizationService.class)
047: .getDocumentAuthorizer(NULL_DOCTYPE);
048: } catch (IllegalArgumentException e) {
049: failedAsExpected = true;
050: }
051:
052: assertTrue(failedAsExpected);
053: }
054:
055: public final void testGetDocumentAuthorizer1_blankDocumentTypeName() {
056: boolean failedAsExpected = false;
057:
058: try {
059: SpringContext.getBean(DocumentAuthorizationService.class)
060: .getDocumentAuthorizer(BLANK_DOCTYPE);
061: } catch (IllegalArgumentException e) {
062: failedAsExpected = true;
063: }
064:
065: assertTrue(failedAsExpected);
066: }
067:
068: public final void testGetDocumentAuthorizer1_unknownDocumentTypeName() {
069: boolean failedAsExpected = false;
070:
071: try {
072: SpringContext.getBean(DocumentAuthorizationService.class)
073: .getDocumentAuthorizer(UNKNOWN_DOCTYPE);
074: } catch (IllegalArgumentException e) {
075: failedAsExpected = true;
076: }
077:
078: assertTrue(failedAsExpected);
079: }
080:
081: public final void testGetDocumentAuthorizer1_knownDocumentTypeName() {
082: DocumentAuthorizer d = SpringContext.getBean(
083: DocumentAuthorizationService.class)
084: .getDocumentAuthorizer(KNOWN_DOCTYPE);
085: assertNotNull(d);
086: }
087:
088: public final void testGetDocumentAuthorizer2_nullDocument() {
089: boolean failedAsExpected = false;
090:
091: try {
092: SpringContext.getBean(DocumentAuthorizationService.class)
093: .getDocumentAuthorizer(NULL_DOCUMENT);
094: } catch (IllegalArgumentException e) {
095: failedAsExpected = true;
096: }
097:
098: assertTrue(failedAsExpected);
099: }
100:
101: public final void testGetDocumentAuthorizer2_uninitializedDocument() {
102: boolean failedAsExpected = false;
103:
104: InternalBillingDocument ibdoc = new InternalBillingDocument();
105: try {
106: SpringContext.getBean(DocumentAuthorizationService.class)
107: .getDocumentAuthorizer(ibdoc);
108: } catch (IllegalArgumentException e) {
109: failedAsExpected = true;
110: }
111:
112: assertTrue(failedAsExpected);
113: }
114:
115: public final void testGetDocumentAuthorizer2_unknownDocumentType() {
116: boolean failedAsExpected = false;
117:
118: try {
119: SpringContext.getBean(DocumentAuthorizationService.class)
120: .getDocumentAuthorizer(new UnknownDocument());
121: } catch (IllegalArgumentException e) {
122: failedAsExpected = true;
123: }
124:
125: assertTrue(failedAsExpected);
126: }
127:
128: public final void testGetDocumentAuthorizer2_knownDocumentTypeName()
129: throws Exception {
130: Document ibdoc = SpringContext.getBean(DocumentService.class)
131: .getNewDocument(KNOWN_DOCTYPE);
132:
133: DocumentAuthorizer d = SpringContext.getBean(
134: DocumentAuthorizationService.class)
135: .getDocumentAuthorizer(ibdoc);
136: assertNotNull(d);
137: }
138:
139: /**
140: * Mock document class for testing
141: */
142: private static final class UnknownDocument extends DocumentBase {
143:
144: protected LinkedHashMap toStringMapper() {
145: return null;
146: }
147:
148: public void populateDocumentForRouting() {
149: }
150:
151: public boolean getAllowsCopy() {
152: return false;
153: }
154: }
155: }
|