Return-Path: X-Original-To: apmail-james-server-dev-archive@www.apache.org Delivered-To: apmail-james-server-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 85E309347 for ; Mon, 12 Dec 2011 11:55:26 +0000 (UTC) Received: (qmail 93848 invoked by uid 500); 12 Dec 2011 11:55:26 -0000 Delivered-To: apmail-james-server-dev-archive@james.apache.org Received: (qmail 93747 invoked by uid 500); 12 Dec 2011 11:55:25 -0000 Mailing-List: contact server-dev-help@james.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "James Developers List" Reply-To: "James Developers List" Delivered-To: mailing list server-dev@james.apache.org Received: (qmail 93739 invoked by uid 500); 12 Dec 2011 11:55:25 -0000 Received: (qmail 93736 invoked by uid 99); 12 Dec 2011 11:55:25 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 12 Dec 2011 11:55:25 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 12 Dec 2011 11:55:24 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 1AD2F23889E2; Mon, 12 Dec 2011 11:55:03 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1213196 [2/2] - in /james/server/trunk/util: ./ src/main/java/org/apache/james/util/retry/ src/main/java/org/apache/james/util/retry/api/ src/main/java/org/apache/james/util/retry/naming/ src/main/java/org/apache/james/util/retry/naming/di... Date: Mon, 12 Dec 2011 11:55:02 -0000 To: server-cvs@james.apache.org From: sbrewin@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20111212115503.1AD2F23889E2@eris.apache.org> Added: james/server/trunk/util/src/test/java/org/apache/james/util/retry/naming/NamingExceptionRetryHandlerTest.java URL: http://svn.apache.org/viewvc/james/server/trunk/util/src/test/java/org/apache/james/util/retry/naming/NamingExceptionRetryHandlerTest.java?rev=1213196&view=auto ============================================================================== --- james/server/trunk/util/src/test/java/org/apache/james/util/retry/naming/NamingExceptionRetryHandlerTest.java (added) +++ james/server/trunk/util/src/test/java/org/apache/james/util/retry/naming/NamingExceptionRetryHandlerTest.java Mon Dec 12 11:55:01 2011 @@ -0,0 +1,137 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +package org.apache.james.util.retry.naming; + +import javax.naming.Context; +import javax.naming.NamingException; + +import org.apache.james.util.retry.api.ExceptionRetryingProxy; +import org.apache.james.util.retry.api.RetryHandler; +import org.apache.james.util.retry.api.RetrySchedule; + +import junit.framework.TestCase; + +/** + * ExceptionRetryHandlerTest + */ +public class NamingExceptionRetryHandlerTest extends TestCase { + + private Class[] _exceptionClasses = null; + private ExceptionRetryingProxy _proxy = null; + private RetrySchedule _schedule = null; + + /** + * @see junit.framework.TestCase#setUp() + */ + @Override + protected void setUp() throws Exception { + super.setUp(); + _exceptionClasses = new Class[]{NamingException.class}; + _proxy = new TestRetryingProxy(); + _schedule = new TestRetrySchedule(); + } + + private class TestRetryingProxy implements ExceptionRetryingProxy + { + + /** + * @see org.apache.james.user.ldap.api.ExceptionRetryingProxy#getDelegate() + */ + @Override + public Context getDelegate() throws NamingException { + return null; + } + + /** + * @see org.apache.james.user.ldap.api.ExceptionRetryingProxy#newDelegate() + */ + @Override + public Context newDelegate() throws NamingException { + return null; + } + + /** + * @see org.apache.james.user.ldap.api.ExceptionRetryingProxy#resetDelegate() + */ + @Override + public void resetDelegate() throws NamingException { + + } + + } + + private class TestRetrySchedule implements RetrySchedule + { + /** + * @see org.apache.james.user.ldap.api.RetrySchedule#getInterval(int) + */ + @Override + public long getInterval(int index) { + return index; + } + + } + + /** + * Test method for {@link org.apache.james.user.ldap.ExceptionRetryHandler#ExceptionRetryHandler(java.lang.Class[], org.apache.james.user.ldap.api.ExceptionRetryingProxy, org.apache.james.user.ldap.api.RetrySchedule, int)}. + */ + public final void testExceptionRetryHandler() { + assertTrue(RetryHandler.class.isAssignableFrom(new NamingExceptionRetryHandler( + _exceptionClasses, _proxy, _schedule, 0) { + + @Override + public Object operation() throws Exception { + return null; + } + }.getClass())); + } + + /** + * Test method for {@link org.apache.james.user.ldap.ExceptionRetryHandler#perform()}. + * @throws Exception + */ + public final void testPerform() throws NamingException { + Object result = new NamingExceptionRetryHandler( + _exceptionClasses, _proxy, _schedule, 0) { + + @Override + public Object operation() throws NamingException { + return "Hi!"; + } + }.perform(); + assertEquals("Hi!", result); + + try { + new NamingExceptionRetryHandler( + _exceptionClasses, _proxy, _schedule, 0) { + + @Override + public Object operation() throws Exception { + throw new NamingException(); + } + }.perform(); + } catch (NamingException ex) { + // no-op + } + assertEquals("Hi!", result); + } + +} Propchange: james/server/trunk/util/src/test/java/org/apache/james/util/retry/naming/NamingExceptionRetryHandlerTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: james/server/trunk/util/src/test/java/org/apache/james/util/retry/naming/NamingExceptionRetryHandlerTest.java ------------------------------------------------------------------------------ svn:mime-type = text/plain --------------------------------------------------------------------- To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org For additional commands, e-mail: server-dev-help@james.apache.org