View Javadoc

1   /*
2    * Copyright 2007-2008 The Kuali Foundation
3    * 
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    * http://www.opensource.org/licenses/ecl2.php
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.kcb.service.impl;
17  
18  import java.util.Collection;
19  
20  import org.junit.Test;
21  import org.kuali.rice.kcb.bo.MessageDelivery;
22  import org.kuali.rice.kcb.deliverer.MessageDeliverer;
23  import org.kuali.rice.kcb.test.KCBTestCase;
24  import org.kuali.rice.kcb.test.TestConstants;
25  import org.kuali.rice.test.BaselineTestCase.BaselineMode;
26  import org.kuali.rice.test.BaselineTestCase.Mode;
27  
28  /**
29   * This class tests the registry service.
30   * @author Kuali Rice Team (rice.collab@kuali.org)
31   */
32  @BaselineMode(Mode.ROLLBACK)
33  public class MessageDelivererRegistryServiceTest extends KCBTestCase {
34      /**
35       * This method tests the hard coded registry list.
36       */
37      @Test
38      public void testGetAllDeliverTypes() {
39          Collection<MessageDeliverer> deliverers = services.getMessageDelivererRegistryService().getAllDeliverers();
40  
41          assertEquals(4, deliverers.size());
42  
43          for(MessageDeliverer deliverer: deliverers) {
44              assertTrue(deliverer.getName() != null);
45              assertTrue(deliverer.getName().length() > 0);
46          }
47      }
48  
49      /**
50       * This method tests a valid deliverer retrieval from the registry.
51       */
52      @Test
53      public void testGetDeliverer_valid() {
54          MessageDelivery mockValid = new MessageDelivery();
55          mockValid.setDelivererTypeName(TestConstants.VALID_DELIVERER_NAME);
56          
57  
58          MessageDeliverer deliverer = services.getMessageDelivererRegistryService().getDeliverer(mockValid);
59          if (deliverer == null) {
60              throw new RuntimeException("Message deliverer could not be obtained");
61          }
62  
63          assertEquals(TestConstants.VALID_DELIVERER_NAME, deliverer.getName());
64      }
65  
66      /**
67       * This method tests a valid deliverer retrieval from the registry.
68       */
69      @Test
70      public void testGetDeliverer_nonExistent() {
71          MessageDelivery mockInvalid = new MessageDelivery();
72          mockInvalid.setDelivererTypeName(TestConstants.NON_EXISTENT_DELIVERER_NAME);
73  
74          boolean caughtException = false;
75  
76          MessageDeliverer deliverer = services.getMessageDelivererRegistryService().getDeliverer(mockInvalid);
77  
78          assertNull(deliverer);
79      }
80  
81      /**
82       * This method tests a valid deliverer retrieval by name.
83       */
84      @Test
85      public void testGetDelivererByName_valid() {
86          MessageDeliverer deliverer = services.getMessageDelivererRegistryService().getDelivererByName(TestConstants.VALID_DELIVERER_NAME);
87  
88          assertEquals(TestConstants.VALID_DELIVERER_NAME, deliverer.getName());
89      }
90  
91      @Test
92      public void testGetDelivererByName_nonExistent() {
93          boolean caughtException = false;
94  
95          MessageDeliverer deliverer = services.getMessageDelivererRegistryService().getDelivererByName(TestConstants.NON_EXISTENT_DELIVERER_NAME);
96  
97          assertNull(deliverer);
98      }
99  }