View Javadoc
1   /**
2    * Copyright 2005-2014 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 org.junit.Test;
19  import org.kuali.rice.kcb.bo.MessageDelivery;
20  import org.kuali.rice.kcb.deliverer.MessageDeliverer;
21  import org.kuali.rice.kcb.test.KCBTestCase;
22  import org.kuali.rice.kcb.test.TestConstants;
23  import org.kuali.rice.test.BaselineTestCase.BaselineMode;
24  import org.kuali.rice.test.BaselineTestCase.Mode;
25  
26  import java.util.Collection;
27  
28  import static org.junit.Assert.*;
29  
30  /**
31   * This class tests the registry service.
32   * @author Kuali Rice Team (rice.collab@kuali.org)
33   */
34  @BaselineMode(Mode.ROLLBACK_CLEAR_DB)
35  public class MessageDelivererRegistryServiceTest extends KCBTestCase {
36      /**
37       * This method tests the hard coded registry list.
38       */
39      @Test
40      public void testGetAllDeliverTypes() {
41          Collection<MessageDeliverer> deliverers = services.getMessageDelivererRegistryService().getAllDeliverers();
42  
43          assertEquals(4, deliverers.size());
44  
45          for(MessageDeliverer deliverer: deliverers) {
46              assertTrue(deliverer.getName() != null);
47              assertTrue(deliverer.getName().length() > 0);
48          }
49      }
50  
51      /**
52       * This method tests a valid deliverer retrieval from the registry.
53       */
54      @Test
55      public void testGetDeliverer_valid() {
56          MessageDelivery mockValid = new MessageDelivery();
57          mockValid.setDelivererTypeName(TestConstants.VALID_DELIVERER_NAME);
58          
59  
60          MessageDeliverer deliverer = services.getMessageDelivererRegistryService().getDeliverer(mockValid);
61          if (deliverer == null) {
62              throw new RuntimeException("Message deliverer could not be obtained");
63          }
64  
65          assertEquals(TestConstants.VALID_DELIVERER_NAME, deliverer.getName());
66      }
67  
68      /**
69       * This method tests a valid deliverer retrieval from the registry.
70       */
71      @Test
72      public void testGetDeliverer_nonExistent() {
73          MessageDelivery mockInvalid = new MessageDelivery();
74          mockInvalid.setDelivererTypeName(TestConstants.NON_EXISTENT_DELIVERER_NAME);
75  
76          boolean caughtException = false;
77  
78          MessageDeliverer deliverer = services.getMessageDelivererRegistryService().getDeliverer(mockInvalid);
79  
80          assertNull(deliverer);
81      }
82  
83      /**
84       * This method tests a valid deliverer retrieval by name.
85       */
86      @Test
87      public void testGetDelivererByName_valid() {
88          MessageDeliverer deliverer = services.getMessageDelivererRegistryService().getDelivererByName(TestConstants.VALID_DELIVERER_NAME);
89  
90          assertEquals(TestConstants.VALID_DELIVERER_NAME, deliverer.getName());
91      }
92  
93      @Test
94      public void testGetDelivererByName_nonExistent() {
95          boolean caughtException = false;
96  
97          MessageDeliverer deliverer = services.getMessageDelivererRegistryService().getDelivererByName(TestConstants.NON_EXISTENT_DELIVERER_NAME);
98  
99          assertNull(deliverer);
100     }
101 }