Michael Hanl | 0320dca | 2016-01-27 21:08:25 +0100 | [diff] [blame] | 1 | import de.ids_mannheim.korap.config.BeanConfiguration; |
| 2 | import de.ids_mannheim.korap.user.KorAPUser; |
| 3 | import de.ids_mannheim.korap.user.User; |
| 4 | import de.ids_mannheim.korap.user.UserDetailsDao; |
| 5 | import de.ids_mannheim.korap.user.Userdetails2; |
| 6 | import org.junit.*; |
| 7 | |
| 8 | /** |
| 9 | * @author hanl |
| 10 | * @date 27/01/2016 |
| 11 | */ |
| 12 | public class UserdataTest { |
| 13 | |
| 14 | @BeforeClass |
| 15 | public static void init() { |
| 16 | BeanConfiguration.loadClasspathContext("default-config.xml"); |
| 17 | } |
| 18 | |
| 19 | @AfterClass |
| 20 | public static void drop() { |
| 21 | BeanConfiguration.closeApplication(); |
| 22 | } |
| 23 | |
| 24 | @Before |
| 25 | public void clear() { |
| 26 | UserDetailsDao dao = new UserDetailsDao( |
| 27 | BeanConfiguration.getBeans().getPersistenceClient()); |
| 28 | assert dao.deleteAll() != -1; |
| 29 | } |
| 30 | |
| 31 | @Test |
| 32 | public void testDataStore() { |
| 33 | User user = new KorAPUser(); |
| 34 | user.setId(1); |
| 35 | UserDetailsDao dao = new UserDetailsDao( |
| 36 | BeanConfiguration.getBeans().getPersistenceClient()); |
| 37 | Userdetails2 d = new Userdetails2(1); |
| 38 | d.addField("key_1", "value is a value"); |
| 39 | assert dao.store(d) != -1; |
| 40 | } |
| 41 | |
| 42 | @Test |
| 43 | public void testDataGet() { |
| 44 | User user = new KorAPUser(); |
| 45 | user.setId(1); |
| 46 | UserDetailsDao dao = new UserDetailsDao( |
| 47 | BeanConfiguration.getBeans().getPersistenceClient()); |
| 48 | Userdetails2 d = new Userdetails2(1); |
| 49 | d.addField("key_1", "value is a value"); |
| 50 | assert dao.store(d) != -1; |
| 51 | |
| 52 | d = dao.get(d.getId()); |
| 53 | assert d != null; |
| 54 | assert "value is a value".equals(d.get("key_1")); |
| 55 | |
| 56 | d = dao.get(user); |
| 57 | assert d != null; |
| 58 | assert "value is a value".equals(d.get("key_1")); |
| 59 | } |
| 60 | |
| 61 | } |