blob: a10a480d76ca364bbadd7683df897ac810619da6 [file] [log] [blame]
Michael Hanl0320dca2016-01-27 21:08:25 +01001import de.ids_mannheim.korap.config.BeanConfiguration;
Michael Hanld034af02016-01-28 14:02:41 +01002import de.ids_mannheim.korap.user.*;
3import org.junit.AfterClass;
4import org.junit.Before;
5import org.junit.BeforeClass;
6import org.junit.Test;
Michael Hanl0320dca2016-01-27 21:08:25 +01007
8/**
9 * @author hanl
10 * @date 27/01/2016
11 */
12public 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
Michael Hanld034af02016-01-28 14:02:41 +010061 @Test
62 public void testUserdatafactory() {
63 UserDataDbIface dao = UserdataFactory
64 .getDaoInstance(Userdetails2.class);
65 assert UserDetailsDao.class.equals(dao.getClass());
66 }
67
68 @Test(expected = RuntimeException.class)
69 public void testUserdatafactoryError() {
70 UserdataFactory.getDaoInstance(new Userdata(1) {
71 @Override
72 public String[] requiredFields() {
73 return new String[0];
74 }
75 }.getClass());
76 }
77
Michael Hanl0320dca2016-01-27 21:08:25 +010078}