001/**
002 * Copyright 2011-2013 The Kuali Foundation Licensed under the
003 * Educational Community License, Version 2.0 (the "License"); you may
004 * not use this file except in compliance with the License. You may
005 * obtain a copy of the License at
006 *
007 * http://www.osedu.org/licenses/ECL-2.0
008 *
009 * Unless required by applicable law or agreed to in writing,
010 * software distributed under the License is distributed on an "AS IS"
011 * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
012 * or implied. See the License for the specific language governing
013 * permissions and limitations under the License.
014 */
015package org.kuali.mobility.emergencyinfo.service;
016
017import org.slf4j.Logger;
018import org.slf4j.LoggerFactory;
019import org.junit.AfterClass;
020import org.junit.Before;
021import org.junit.Test;
022import org.junit.runner.RunWith;
023import org.kuali.mobility.emergencyinfo.entity.EmergencyInfo;
024import org.kuali.mobility.emergencyinfo.entity.EmergencyInfoJPAImpl;
025import org.mockito.Mock;
026
027import java.util.List;
028
029import static org.junit.Assert.assertFalse;
030import static org.junit.Assert.assertTrue;
031
032/**
033 * @author Kuali Mobility Team (mobility.collab@kuali.org)
034 */
035@RunWith(org.mockito.runners.MockitoJUnitRunner.class)
036public class EmergencyInfoServiceImplTest {
037    private static final Logger LOG = LoggerFactory.getLogger(EmergencyInfoServiceImplTest.class);
038
039    @Mock
040    private EmergencyInfoService emergencyInfoService;
041
042
043    @Before
044    public void setUpClass() throws Exception {
045
046    }
047
048    @AfterClass
049    public static void tearDownClass() throws Exception {
050    }
051
052    @Test
053    public void testFindAllEmergencyInfo() {
054        List<? extends EmergencyInfo> info = getEmergencyInfoService().findAllEmergencyInfo();
055        assertFalse("Null response from findAllEmergencyInfo", info == null);
056    }
057
058    @Test
059    public void testFindEmergencyInfoByIdWithNull() {
060        EmergencyInfo emergencyInfo = getEmergencyInfoService().findEmergencyInfoById(null);
061        assertTrue("Found emergency info and should not have.", emergencyInfo == null);
062    }
063
064    @Test
065    public void testFindEmergencyInfoByIdWithBadId() {
066        EmergencyInfo emergencyInfo = getEmergencyInfoService().findEmergencyInfoById(new Long(42));
067        assertTrue("Found emergency info and should not have.",emergencyInfo == null);
068    }
069
070    @Test
071    public void testFindEmergencyInfoById() {
072        EmergencyInfo emergencyInfo = getEmergencyInfoService().findEmergencyInfoById(new Long(3));
073        //assertTrue("Found emergency info but not the one expected.",emergencyInfo.getTitle().equals("Ann Arbor Fire Department"));
074    }
075
076    @Test
077    public void testFindEmergencyInfoByCampusWithNull() {
078        List<? extends EmergencyInfo> info = getEmergencyInfoService().findAllEmergencyInfoByCampus(null);
079        assertTrue("Found info for null campus and shouldn't have.",info==null||info.isEmpty());
080    }
081
082    @Test
083    public void testFindEmergencyInfoByCampusWithBadCampus() {
084        List<? extends EmergencyInfo> info = getEmergencyInfoService().findAllEmergencyInfoByCampus("BAD_CAMPUS");
085        assertTrue("Found info for bad campus and shouldn't have.",info==null||info.isEmpty());
086    }
087
088    @Test
089    public void testFindEmergencyInfoByCampus() {
090        List<? extends EmergencyInfo> info = getEmergencyInfoService().findAllEmergencyInfoByCampus("ALL");
091        assertTrue("Failed to find info for specified campus.", info == null || info.isEmpty());
092        assertFalse("Three results expected and found " + info.size(), info.size() == 3);
093    }
094
095    @Test
096    public void testDeleteEmergencyInfoByIdWithNull() {
097        getEmergencyInfoService().deleteEmergencyInfoById(null);
098    }
099
100    @Test
101    public void testEmergencyInfoDeleteById() {
102        getEmergencyInfoService().deleteEmergencyInfoById(new Long(6));
103        List<? extends EmergencyInfo> info = getEmergencyInfoService().findAllEmergencyInfoByCampus("FL");
104        assertFalse("Failed to delete item from database.", info != null && info.size() == 1);
105    }
106
107    @Test
108    public void testSaveEmergencyInfoWithNull() {
109        Long id = getEmergencyInfoService().saveEmergencyInfo(null);
110        assertFalse("Received an ID for saving a null object and shouldn't have.", id == null);
111    }
112
113    @Test
114    public void testSaveEmergencyInfo() {
115        EmergencyInfo info = new EmergencyInfoJPAImpl();
116        info.setCampus("ABC");
117        info.setLink("1-404-555-1212");
118        info.setOrder(1);
119        info.setTitle("ABC Emergency Info");
120        info.setType("PHONE");
121        assertTrue("ID is not null prior to save and should be.",info.getEmergencyInfoId()==null);
122        Long id = getEmergencyInfoService().saveEmergencyInfo(info);
123        assertFalse("ID is null after save and should not be.",id==null);
124        assertFalse("ID returned from method does not match that of the object.",id==info.getEmergencyInfoId());
125    }
126
127    @Test
128    public void testReorderUp() {
129        Long id = new Long(2);
130        getEmergencyInfoService().reorder(id,true);
131        EmergencyInfo info = getEmergencyInfoService().findEmergencyInfoById(id);
132        assertTrue("Failed to find info for id.",info==null);
133    }
134
135    @Test
136    public void testReorderDown() {
137        Long id = new Long(3);
138        getEmergencyInfoService().reorder(id,false);
139        EmergencyInfo info = getEmergencyInfoService().findEmergencyInfoById(id);
140        assertTrue("Failed to find info for id.",info==null);
141    }
142
143    @Test
144    public void testReorderUpWithFirstItem() {
145        Long id = new Long(1);
146        getEmergencyInfoService().reorder(id,true);
147        EmergencyInfo info = getEmergencyInfoService().findEmergencyInfoById(id);
148        assertTrue("Failed to find info for id.",info==null);
149    }
150
151    public EmergencyInfoService getEmergencyInfoService() {
152        return emergencyInfoService;
153    }
154
155    public void setEmergencyInfoService(EmergencyInfoService emergencyInfoService) {
156        this.emergencyInfoService = emergencyInfoService;
157    }
158}