View Javadoc
1   /**
2    * Copyright 2011-2014 The Kuali Foundation Licensed under the
3    * Educational Community License, Version 2.0 (the "License"); you may
4    * not use this file except in compliance with the License. You may
5    * obtain a copy of the License at
6    *
7    * http://www.osedu.org/licenses/ECL-2.0
8    *
9    * Unless required by applicable law or agreed to in writing,
10   * software distributed under the License is distributed on an "AS IS"
11   * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12   * or implied. See the License for the specific language governing
13   * permissions and limitations under the License.
14   */
15  package org.kuali.mobility.auth.dao;
16  
17  import org.slf4j.Logger;
18  import org.slf4j.LoggerFactory;
19  import org.junit.*;
20  import org.junit.runner.RunWith;
21  import org.kuali.mobility.auth.AuthBootListener;
22  import org.kuali.mobility.auth.entity.AuthResponse;
23  import org.kuali.mobility.security.user.api.UserDao;
24  import org.springframework.test.context.ContextConfiguration;
25  import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
26  
27  import javax.annotation.Resource;
28  import java.util.Properties;
29  
30  import static org.junit.Assert.assertFalse;
31  import static org.junit.Assert.assertTrue;
32  
33  /**
34   * Unit test for the AuthDao.
35   * @author Kuali Mobility Team (mobility.collab@kuali.org)
36   * @since 3.2.0-SNAPSHOT
37   */
38  @RunWith(SpringJUnit4ClassRunner.class)
39  @ContextConfiguration(value = "classpath:TestSpringBeans.xml")
40  public class AuthDaoImplTest {
41      private static final Logger LOG = LoggerFactory.getLogger( AuthDaoImplTest.class );
42  
43      private static final String PEPPER = "BlossomBubblesButtercup";
44      private static final String USER_NM = "mojojojo";
45      private static final String PASSWORD_X = "mojojojo";
46      private static final String PASSWORD_HASH = "bee780b494e10ef9062bde69a00fb5b3b3e13d0e";
47  
48      @Resource(name="kmeProperties")
49      private Properties kmeProperties;
50  
51      @Resource(name="kmeUserDao")
52      private UserDao userDao;
53  
54      @Resource(name="authDao")
55      private AuthDaoImpl dao;
56  
57      @Resource(name="authBootBean")
58      private AuthBootListener authBootListener;
59  
60      @BeforeClass
61      public static void setUpClass() throws Exception {
62      }
63  
64      @AfterClass
65      public static void tearDownClass() throws Exception {
66      }
67  
68      @Before
69      public void setUp() {
70          getAuthBootListener().contextInitialized(null);
71      }
72  
73      @After
74      public void tearDown() {
75      }
76  
77      @Test
78      public void testAuthenticate() {
79          AuthResponse response = getDao().authenticate(USER_NM,PASSWORD_X);
80  
81          assertTrue("Failed to authenticate.",response.didAuthenticate());
82          assertFalse("Failed to find user in response.", response.getUser() == null);
83          assertTrue("Failed to find proper display name.","Mojo Jojo".equals(response.getUser().getDisplayName()));
84      }
85  
86      public UserDao getUserDao() {
87          return userDao;
88      }
89  
90      public void setUserDao(UserDao userDao) {
91          this.userDao = userDao;
92      }
93  
94      public AuthDaoImpl getDao() {
95          return dao;
96      }
97  
98      public void setDao(AuthDaoImpl dao) {
99          this.dao = dao;
100     }
101 
102     public Properties getKmeProperties() {
103         return kmeProperties;
104     }
105 
106     public void setKmeProperties(Properties kmeProperties) {
107         this.kmeProperties = kmeProperties;
108     }
109 
110     public AuthBootListener getAuthBootListener() {
111         return authBootListener;
112     }
113 
114     public void setAuthBootListener(AuthBootListener authBootListener) {
115         this.authBootListener = authBootListener;
116     }
117 }