001    /**
002     * Copyright 2005-2011 The Kuali Foundation
003     *
004     * Licensed under the Educational Community License, Version 2.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/ecl2.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.rice.kew.rule;
017    
018    import static org.junit.Assert.assertTrue;
019    import static org.junit.Assert.fail;
020    
021    import org.junit.Test;
022    import org.kuali.rice.core.api.config.property.Config;
023    import org.kuali.rice.core.api.config.property.ConfigContext;
024    import org.kuali.rice.kew.api.WorkflowDocument;
025    import org.kuali.rice.kew.api.WorkflowDocumentFactory;
026    import org.kuali.rice.kew.test.KEWTestCase;
027    import org.kuali.rice.ksb.util.KSBConstants;
028    
029    /**
030     * Tests the generation of Action Requests from RoleAttributes
031     *
032     * @author Kuali Rice Team (rice.collab@kuali.org)
033     */
034    public class RoleAttributeTest extends KEWTestCase {
035    
036            @Test public void testWorkgroupRoleAttribute() throws Exception {
037                    loadXmlFile("WorkgroupRoleAttributeTestConfig.xml");
038                    WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("user1"), "WorkgroupRoleAttributeDocument");
039                    document.route("");
040    
041                    assertTrue("document should be enroute.", document.isEnroute());
042            }
043    
044            /**
045             * Tests that if you return a non-null Id object with a null id value inside, that the role action request
046             * generation handles it properly.
047             */
048            @Test public void testBadWorkgroupRoleAttribute() throws Exception {
049                    loadXmlFile("BadWorkgroupRoleAttributeTestConfig.xml");
050                    WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("user1"), "BadWorkgroupRoleAttributeDocument");
051    
052    
053            ConfigContext.getCurrentContextConfig().putProperty(KSBConstants.Config.ALLOW_SYNC_EXCEPTION_ROUTING, "false");
054                    try {
055                            document.route("");
056                            fail("Should have thrown an error because we had some bad ids.");
057                    } catch (Exception e) {
058            } finally {
059                // be sure to change it back afterward!
060                ConfigContext.getCurrentContextConfig().putProperty(KSBConstants.Config.ALLOW_SYNC_EXCEPTION_ROUTING, "true");
061            }
062            }
063    }