001: /*
002: * Copyright 2005-2006 The Kuali Foundation.
003: *
004: *
005: * Licensed under the Educational Community License, Version 1.0 (the "License");
006: * you may not use this file except in compliance with the License.
007: * You may obtain a copy of the License at
008: *
009: * http://www.opensource.org/licenses/ecl1.php
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package edu.iu.uis.eden.messaging.exceptionhandling;
018:
019: import org.junit.Test;
020: import org.kuali.bus.test.KSBTestCase;
021: import org.kuali.rice.RiceConstants;
022: import org.kuali.rice.core.Core;
023:
024: import edu.iu.uis.eden.messaging.AsynchronousCall;
025: import edu.iu.uis.eden.messaging.JavaServiceDefinition;
026: import edu.iu.uis.eden.messaging.PersistedMassagePayload;
027: import edu.iu.uis.eden.messaging.PersistedMessage;
028: import edu.iu.uis.eden.messaging.ServiceInfo;
029:
030: public class DefaultMessageExceptionHandlerTest extends KSBTestCase {
031:
032: private PersistedMessage setupMessage(Integer retriesAttempted,
033: Integer serviceMaxRetries) throws Exception {
034: PersistedMessage message = new PersistedMessage();
035: message.setRetryCount(retriesAttempted);
036: ServiceInfo serviceInfo = new ServiceInfo();
037: serviceInfo.setServiceDefinition(new JavaServiceDefinition());
038: serviceInfo.getServiceDefinition().setRetryAttempts(
039: serviceMaxRetries);
040: AsynchronousCall methodCall = new AsynchronousCall(
041: new Class[0], new Object[0], serviceInfo, "", null,
042: null);
043: message.setPayload(new PersistedMassagePayload(methodCall,
044: message));
045: message.setMethodCall(methodCall);
046: return message;
047: }
048:
049: private void setMaxRetries(String maxRetries) {
050: Core
051: .getCurrentContextConfig()
052: .overrideProperty(
053: RiceConstants.ROUTE_QUEUE_MAX_RETRY_ATTEMPTS_OVERRIDE_KEY,
054: maxRetries);
055: }
056:
057: @Test
058: public void testGetGlobalMaxRetryAttempts() throws Exception {
059: DefaultMessageExceptionHandler exceptionHandler = new DefaultMessageExceptionHandler();
060:
061: this .setMaxRetries("0");
062:
063: // test non-numeric
064: this .setMaxRetries("B");
065: assertNull(
066: "Method should return null if app constant is non-numeric.",
067: exceptionHandler.getGlobalMaxRetryAttempts());
068:
069: // test large negative number
070: this .setMaxRetries("-10");
071: assertNull(
072: "Method should return null if app constant is negative number.",
073: exceptionHandler.getGlobalMaxRetryAttempts());
074:
075: // test -1
076: this .setMaxRetries("-1");
077: assertNull(
078: "Method should return null if app constant is negative number.",
079: exceptionHandler.getGlobalMaxRetryAttempts());
080:
081: // test 0
082: this .setMaxRetries("0");
083: assertEquals(
084: "Method should return app constant value if app constant is numeric and greater than or equal to zero.",
085: new Integer(0), exceptionHandler
086: .getGlobalMaxRetryAttempts());
087:
088: // test 1
089: this .setMaxRetries("1");
090: assertEquals(
091: "Method should return app constant value if app constant is numeric and greater than or equal to zero.",
092: new Integer(1), exceptionHandler
093: .getGlobalMaxRetryAttempts());
094:
095: // test 5
096: this .setMaxRetries("5");
097: assertEquals(
098: "Method should return app constant value if app constant is numeric and greater than or equal to zero.",
099: new Integer(5), exceptionHandler
100: .getGlobalMaxRetryAttempts());
101: }
102:
103: @Test
104: public void testIsInException() throws Exception {
105: DefaultMessageExceptionHandler exceptionHandler = new DefaultMessageExceptionHandler();
106: PersistedMessage message = null;
107:
108: this .setMaxRetries("-10");
109:
110: message = setupMessage(0, 1);
111: assertFalse(exceptionHandler.isInException(message));
112:
113: message.setRetryCount(1);
114: assertTrue(exceptionHandler.isInException(message));
115:
116: message.setRetryCount(2);
117: assertTrue(exceptionHandler.isInException(message));
118:
119: this .setMaxRetries("5");
120:
121: message.setRetryCount(4);
122: assertFalse(exceptionHandler.isInException(message));
123:
124: message.setRetryCount(5);
125: assertTrue(exceptionHandler.isInException(message));
126:
127: message.setRetryCount(6);
128: assertTrue(exceptionHandler.isInException(message));
129:
130: this .setMaxRetries("0");
131:
132: message.setRetryCount(0);
133: assertTrue(exceptionHandler.isInException(message));
134:
135: message.setRetryCount(1);
136: assertTrue(exceptionHandler.isInException(message));
137:
138: this .setMaxRetries("-1");
139:
140: message.setRetryCount(0);
141: assertFalse(exceptionHandler.isInException(message));
142:
143: message = setupMessage(1, 5);
144: assertFalse(exceptionHandler.isInException(message));
145:
146: this .setMaxRetries("B");
147:
148: message.setRetryCount(0);
149: assertFalse(exceptionHandler.isInException(message));
150: }
151:
152: }
|