blob: ea47a994ea5991cb9ec99a02c86c4c9c702241e2 [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
Michael Hanlc2a9f622016-01-28 16:40:06 +010062 public void testDataValidation() {
63 Userdata data = new Userdetails2(1);
64 data.addField(Attributes.COUNTRY, "Germany");
65
66 String[] req = data.requiredFields();
67 String[] r = data.validationReturn();
68 assert r.length > 0;
69 assert r.length == req.length;
70 assert !data.isValid();
71 }
72
73 @Test
Michael Hanld034af02016-01-28 14:02:41 +010074 public void testUserdatafactory() {
75 UserDataDbIface dao = UserdataFactory
76 .getDaoInstance(Userdetails2.class);
77 assert UserDetailsDao.class.equals(dao.getClass());
78 }
79
80 @Test(expected = RuntimeException.class)
81 public void testUserdatafactoryError() {
82 UserdataFactory.getDaoInstance(new Userdata(1) {
83 @Override
84 public String[] requiredFields() {
85 return new String[0];
86 }
87 }.getClass());
88 }
89
Michael Hanl0320dca2016-01-27 21:08:25 +010090}