1
1
package com .logicaldoc .core .metadata ;
2
2
3
+ import static org .junit .Assert .assertEquals ;
4
+ import static org .junit .Assert .assertFalse ;
5
+ import static org .junit .Assert .assertNotNull ;
6
+ import static org .junit .Assert .assertNotSame ;
7
+ import static org .junit .Assert .assertNull ;
8
+ import static org .junit .Assert .assertTrue ;
9
+
3
10
import java .io .IOException ;
4
11
import java .sql .SQLException ;
5
12
import java .util .Collection ;
13
+ import java .util .Set ;
6
14
7
15
import org .junit .Before ;
8
16
import org .junit .Test ;
9
17
10
18
import com .logicaldoc .core .AbstractCoreTestCase ;
11
19
import com .logicaldoc .core .PersistenceException ;
20
+ import com .logicaldoc .core .security .Permission ;
12
21
import com .logicaldoc .core .security .Tenant ;
13
22
import com .logicaldoc .util .Context ;
14
23
import com .logicaldoc .util .plugin .PluginException ;
15
24
16
- import junit .framework .Assert ;
17
-
18
25
/**
19
26
* Test case for {@link HibernateTemplateDAO}
20
27
*
@@ -40,73 +47,73 @@ public void testDelete() throws PersistenceException {
40
47
try {
41
48
testSubject .delete (1 );
42
49
} catch (PersistenceException e ) {
43
- Assert . assertTrue (true );
50
+ assertTrue (true );
44
51
}
45
52
46
53
testSubject .delete (-1L );
47
54
Template template = testSubject .findById (-1L );
48
- Assert . assertNull (template );
55
+ assertNull (template );
49
56
}
50
57
51
58
@ Test
52
59
public void testFindAll () throws PersistenceException {
53
60
Collection <Template > templates = testSubject .findAll ();
54
- Assert . assertNotNull (templates );
55
- Assert . assertEquals (4 , templates .size ());
61
+ assertNotNull (templates );
62
+ assertEquals (4 , templates .size ());
56
63
}
57
64
58
65
@ Test
59
66
public void testFindById () throws PersistenceException {
60
67
Template template = testSubject .findById (1 );
61
- Assert . assertNotNull (template );
68
+ assertNotNull (template );
62
69
testSubject .initialize (template );
63
- Assert . assertEquals (1 , template .getId ());
64
- Assert . assertEquals ("test1" , template .getName ());
65
- Assert . assertTrue (template .getAttributes ().containsKey ("attr1" ));
70
+ assertEquals (1 , template .getId ());
71
+ assertEquals ("test1" , template .getName ());
72
+ assertTrue (template .getAttributes ().containsKey ("attr1" ));
66
73
67
74
// Try with unexisting template
68
75
template = testSubject .findById (99 );
69
- Assert . assertNull (template );
76
+ assertNull (template );
70
77
71
78
template = testSubject .findById (-1 );
72
- Assert . assertNotNull (template );
79
+ assertNotNull (template );
73
80
testSubject .initialize (template );
74
- Assert . assertEquals (-1 , template .getId ());
75
- Assert . assertEquals ("default" , template .getName ());
76
- Assert . assertTrue (template .getAttributes ().containsKey ("object" ));
81
+ assertEquals (-1 , template .getId ());
82
+ assertEquals ("default" , template .getName ());
83
+ assertTrue (template .getAttributes ().containsKey ("object" ));
77
84
}
78
85
79
86
@ Test
80
87
public void testClone () throws PersistenceException {
81
88
Template template = testSubject .findById (1 );
82
- Assert . assertNotNull (template );
89
+ assertNotNull (template );
83
90
testSubject .initialize (template );
84
- Assert . assertEquals (1 , template .getId ());
85
- Assert . assertEquals ("test1" , template .getName ());
86
- Assert . assertTrue (template .getAttributes ().containsKey ("attr1" ));
91
+ assertEquals (1 , template .getId ());
92
+ assertEquals ("test1" , template .getName ());
93
+ assertTrue (template .getAttributes ().containsKey ("attr1" ));
87
94
88
95
Template clone = testSubject .clone (1 , "test1-Clone" );
89
- Assert . assertNotNull (clone );
96
+ assertNotNull (clone );
90
97
clone = testSubject .findById (clone .getId ());
91
98
testSubject .initialize (clone );
92
- Assert . assertNotSame (1 , clone .getId ());
93
- Assert . assertEquals ("test1-Clone" , clone .getName ());
94
- Assert . assertTrue (clone .getAttributes ().containsKey ("attr1" ));
99
+ assertNotSame (1 , clone .getId ());
100
+ assertEquals ("test1-Clone" , clone .getName ());
101
+ assertTrue (clone .getAttributes ().containsKey ("attr1" ));
95
102
}
96
103
97
104
@ Test
98
105
public void testFindByName () throws PersistenceException {
99
106
Template template = testSubject .findByName ("test1" , Tenant .DEFAULT_ID );
100
- Assert . assertNotNull (template );
107
+ assertNotNull (template );
101
108
testSubject .initialize (template );
102
- Assert . assertEquals (1 , template .getId ());
103
- Assert . assertEquals ("test1" , template .getName ());
109
+ assertEquals (1 , template .getId ());
110
+ assertEquals ("test1" , template .getName ());
104
111
105
112
template = testSubject .findByName ("xxx" , Tenant .DEFAULT_ID );
106
- Assert . assertNull (template );
113
+ assertNull (template );
107
114
108
115
template = testSubject .findByName ("test1" , 99L );
109
- Assert . assertNull (template );
116
+ assertNull (template );
110
117
}
111
118
112
119
@ Test
@@ -118,38 +125,40 @@ public void testStore() throws PersistenceException {
118
125
template .setValue ("object" , "value" );
119
126
120
127
testSubject .store (template );
121
- Assert . assertNotNull (template );
128
+ assertNotNull (template );
122
129
template = testSubject .findById (template .getId ());
123
- Assert . assertNotNull (template );
130
+ assertNotNull (template );
124
131
testSubject .initialize (template );
125
- Assert . assertEquals ("test3" , template .getName ());
126
- Assert . assertTrue (template .getTemplateAttributes ().containsKey ("a1" ));
127
- Assert . assertTrue (template .getTemplateAttributes ().containsKey ("a2" ));
128
- Assert . assertTrue (template .getTemplateAttributes ().containsKey ("object" ));
132
+ assertEquals ("test3" , template .getName ());
133
+ assertTrue (template .getTemplateAttributes ().containsKey ("a1" ));
134
+ assertTrue (template .getTemplateAttributes ().containsKey ("a2" ));
135
+ assertTrue (template .getTemplateAttributes ().containsKey ("object" ));
129
136
}
130
137
131
138
@ Test
132
139
public void testPermissions () throws PersistenceException {
133
140
Template template = testSubject .findById (1L );
134
- Assert . assertNotNull (template );
141
+ assertNotNull (template );
135
142
136
- Assert . assertTrue (testSubject .isReadEnable (1L , 1L ));
137
- Assert . assertTrue (testSubject .isWriteEnable (1L , 1L ));
143
+ assertTrue (testSubject .isReadEnable (1L , 1L ));
144
+ assertTrue (testSubject .isWriteEnable (1L , 1L ));
138
145
139
- Assert . assertTrue (testSubject .isReadEnable (1L , 3L ));
140
- Assert . assertTrue (testSubject .isWriteEnable (1L , 3L ));
146
+ assertTrue (testSubject .isReadEnable (1L , 3L ));
147
+ assertTrue (testSubject .isWriteEnable (1L , 3L ));
141
148
142
- Assert . assertFalse (testSubject .isReadEnable (1L , 5L ));
143
- Assert . assertFalse (testSubject .isWriteEnable (1L , 5L ));
149
+ assertFalse (testSubject .isReadEnable (1L , 5L ));
150
+ assertFalse (testSubject .isWriteEnable (1L , 5L ));
144
151
145
- Assert . assertFalse (testSubject .isReadEnable (1L , 99L ));
146
- Assert . assertFalse (testSubject .isReadEnable (2L , 99L ));
152
+ assertFalse (testSubject .isReadEnable (1L , 99L ));
153
+ assertFalse (testSubject .isReadEnable (2L , 99L ));
147
154
148
- Assert .assertFalse (testSubject .isReadEnable (1L , 4L ));
149
- Assert .assertFalse (testSubject .isWriteEnable (1L , 4L ));
150
-
151
- Assert .assertFalse (testSubject .isReadEnable (2L , 4L ));
152
- Assert .assertFalse (testSubject .isWriteEnable (2L , 4L ));
155
+ assertFalse (testSubject .isReadEnable (1L , 4L ));
156
+ assertFalse (testSubject .isWriteEnable (1L , 4L ));
153
157
158
+ assertFalse (testSubject .isReadEnable (2L , 4L ));
159
+ assertFalse (testSubject .isWriteEnable (2L , 4L ));
160
+
161
+ Set <Permission > permissions = testSubject .getAllowedPermissions (1L , 1L );
162
+ assertEquals (Permission .all ().size (), permissions .size ());
154
163
}
155
164
}
0 commit comments