18
18
19
19
package org .mycore .mir .acl ;
20
20
21
+ import static org .junit .jupiter .api .Assertions .assertFalse ;
22
+ import static org .junit .jupiter .api .Assertions .assertTrue ;
23
+
21
24
import java .util .Arrays ;
22
25
import java .util .List ;
23
- import java .util .Map ;
24
26
import java .util .stream .Collectors ;
25
27
import java .util .stream .Stream ;
26
28
27
-
28
- import org .junit .Assert ;
29
+ import org .junit .jupiter .api .BeforeEach ;
29
30
import org .mycore .access .facts .MCRFactsAccessSystem ;
30
31
import org .mycore .access .facts .fact .MCRStringFact ;
31
32
import org .mycore .access .facts .model .MCRFact ;
32
- import org .mycore .common .MCRStoreTestCase ;
33
33
import org .mycore .common .config .MCRConfiguration2 ;
34
34
35
- public class MIRACLTest extends MCRStoreTestCase {
35
+ public abstract class MIRACLTest {
36
36
37
37
MCRFactsAccessSystem accessSystem ;
38
38
@@ -44,9 +44,9 @@ public void disableDebug() {
44
44
//Configurator.setLevel(LogManager.getLogger(MCRFactsAccessSystem.class).getName(), Level.INFO);
45
45
}
46
46
47
- @ Override
48
- public void setUp () throws Exception {
49
- super . setUp ();
47
+ @ BeforeEach
48
+ public void setUp () {
49
+ setTestProperties ();
50
50
accessSystem = MCRConfiguration2 .getInstanceOfOrThrow (MCRFactsAccessSystem .class , "MCR.Access.Class" );
51
51
}
52
52
@@ -55,11 +55,10 @@ protected void checkWebpage(String webpageURL, boolean shouldBeAbleToRead, Strin
55
55
Arrays .stream (userRole ).map (role -> new MCRStringFact ("role" , role )).collect (Collectors .toList ()));
56
56
57
57
if (shouldBeAbleToRead ) {
58
- Assert .assertTrue (String .join ("," , userRole ) + " should be able to open the webpage " + webpageURL ,
59
- hasPermission );
58
+ assertTrue (hasPermission , String .join ("," , userRole ) + " should be able to open the webpage " + webpageURL );
60
59
} else {
61
- Assert . assertFalse (String . join ( "," , userRole ) + " should not be able to open the webpage " + webpageURL ,
62
- hasPermission );
60
+ assertFalse (hasPermission ,
61
+ String . join ( "," , userRole ) + " should not be able to open the webpage " + webpageURL );
63
62
}
64
63
}
65
64
@@ -68,9 +67,9 @@ protected void checkReadId(String id, boolean shouldBeAbleToRead, String... user
68
67
Arrays .stream (userRole ).map (role -> new MCRStringFact ("role" , role )).collect (Collectors .toList ()));
69
68
70
69
if (shouldBeAbleToRead ) {
71
- Assert . assertTrue (String .join ("," , userRole ) + " should be able to read the id " + id , hasPermission );
70
+ assertTrue (hasPermission , String .join ("," , userRole ) + " should be able to read the id " + id );
72
71
} else {
73
- Assert . assertFalse (String .join ("," , userRole ) + " should not be able to read the id " + id , hasPermission );
72
+ assertFalse (hasPermission , String .join ("," , userRole ) + " should not be able to read the id " + id );
74
73
}
75
74
}
76
75
@@ -98,9 +97,9 @@ public void testPermission(String user, String action, boolean shouldBeAbleTo, S
98
97
boolean hasPermission = accessSystem .checkPermission (null , action , facts );
99
98
100
99
if (shouldBeAbleTo ) {
101
- Assert . assertTrue (user + " should be able to " + action , hasPermission );
100
+ assertTrue (hasPermission , user + " should be able to " + action );
102
101
} else {
103
- Assert . assertFalse (user + " should not be able to " + action , hasPermission );
102
+ assertFalse (hasPermission , user + " should not be able to " + action );
104
103
}
105
104
}
106
105
@@ -130,9 +129,9 @@ public void testObject(String user, String creator, String status, String id, bo
130
129
boolean hasPermission = accessSystem .checkPermission (id , action , facts );
131
130
132
131
if (shouldBeAbleTo ) {
133
- Assert . assertTrue (user + " should be able to " + action + " the id " + id , hasPermission );
132
+ assertTrue (hasPermission , user + " should be able to " + action + " the id " + id );
134
133
} else {
135
- Assert . assertFalse (user + " should not be able to " + action + " the id " + id , hasPermission );
134
+ assertFalse (hasPermission , user + " should not be able to " + action + " the id " + id );
136
135
}
137
136
}
138
137
@@ -149,65 +148,62 @@ public void testReadWriteObject(String user, String creator, String status, Stri
149
148
testReadWriteObject (user , creator , status , id , shouldBeAbleToReadWrite , read , role , embargo , false , false );
150
149
}
151
150
152
- @ Override
153
- protected Map <String , String > getTestProperties () {
154
- Map <String , String > testProperties = super .getTestProperties ();
151
+ private void setTestProperties () {
155
152
156
- testProperties . put ("MCR.Metadata.Type.mods" , "true" );
157
- testProperties . put ("MCR.Metadata.Type.derivate" , "true" );
153
+ MCRConfiguration2 . set ("MCR.Metadata.Type.mods" , "true" );
154
+ MCRConfiguration2 . set ("MCR.Metadata.Type.derivate" , "true" );
158
155
159
- testProperties . put ("MCR.Access.Facts.Condition.and" ,
156
+ MCRConfiguration2 . set ("MCR.Access.Facts.Condition.and" ,
160
157
"org.mycore.access.facts.condition.combined.MCRAndCondition" );
161
- testProperties . put ("MCR.Access.Facts.Condition.or" ,
158
+ MCRConfiguration2 . set ("MCR.Access.Facts.Condition.or" ,
162
159
"org.mycore.access.facts.condition.combined.MCROrCondition" );
163
- testProperties . put ("MCR.Access.Facts.Condition.not" ,
160
+ MCRConfiguration2 . set ("MCR.Access.Facts.Condition.not" ,
164
161
"org.mycore.access.facts.condition.combined.MCRNotCondition" );
165
- testProperties . put ("MCR.Access.Facts.Condition.id" ,
162
+ MCRConfiguration2 . set ("MCR.Access.Facts.Condition.id" ,
166
163
"org.mycore.access.facts.condition.fact.MCRStringCondition" );
167
- testProperties . put ("MCR.Access.Facts.Condition.target" ,
164
+ MCRConfiguration2 . set ("MCR.Access.Facts.Condition.target" ,
168
165
"org.mycore.access.facts.condition.fact.MCRStringCondition" );
169
- testProperties . put ("MCR.Access.Facts.Condition.action" ,
166
+ MCRConfiguration2 . set ("MCR.Access.Facts.Condition.action" ,
170
167
"org.mycore.access.facts.condition.fact.MCRStringCondition" );
171
- testProperties . put ("MCR.Access.Facts.Condition.user" ,
168
+ MCRConfiguration2 . set ("MCR.Access.Facts.Condition.user" ,
172
169
"org.mycore.access.facts.condition.fact.MCRUserCondition" );
173
- testProperties . put ("MCR.Access.Facts.Condition.role" ,
170
+ MCRConfiguration2 . set ("MCR.Access.Facts.Condition.role" ,
174
171
"org.mycore.access.facts.condition.fact.MCRRoleCondition" );
175
- testProperties . put ("MCR.Access.Facts.Condition.ip" , "org.mycore.access.facts.condition.fact.MCRIPCondition" );
176
- testProperties . put ("MCR.Access.Facts.Condition.status" ,
172
+ MCRConfiguration2 . set ("MCR.Access.Facts.Condition.ip" , "org.mycore.access.facts.condition.fact.MCRIPCondition" );
173
+ MCRConfiguration2 . set ("MCR.Access.Facts.Condition.status" ,
177
174
"org.mycore.access.facts.condition.fact.MCRStateCondition" );
178
- testProperties . put ("MCR.Access.Facts.Condition.createdby" ,
175
+ MCRConfiguration2 . set ("MCR.Access.Facts.Condition.createdby" ,
179
176
"org.mycore.access.facts.condition.fact.MCRCreatedByCondition" );
180
- testProperties . put ("MCR.Access.Facts.Condition.regex" ,
177
+ MCRConfiguration2 . set ("MCR.Access.Facts.Condition.regex" ,
181
178
"org.mycore.access.facts.condition.fact.MCRRegExCondition" );
182
- testProperties . put ("MCR.Access.Facts.Condition.category" ,
179
+ MCRConfiguration2 . set ("MCR.Access.Facts.Condition.category" ,
183
180
"org.mycore.access.facts.condition.fact.MCRCategoryCondition" );
184
- testProperties . put ("MCR.Access.Facts.Condition.collection" ,
181
+ MCRConfiguration2 . set ("MCR.Access.Facts.Condition.collection" ,
185
182
"org.mycore.mods.access.facts.condition.MCRMODSCollectionCondition" );
186
- testProperties . put ("MCR.Access.Facts.Condition.genre" ,
183
+ MCRConfiguration2 . set ("MCR.Access.Facts.Condition.genre" ,
187
184
"org.mycore.mods.access.facts.condition.MCRMODSGenreCondition" );
188
- testProperties . put ("MCR.Access.Facts.Condition.embargo" ,
185
+ MCRConfiguration2 . set ("MCR.Access.Facts.Condition.embargo" ,
189
186
"org.mycore.mods.access.facts.condition.MCRMODSEmbargoCondition" );
190
187
191
- testProperties . put ("MCR.URIResolver.ModuleResolver.property" , "org.mycore.common.xml.MCRPropertiesResolver" );
192
- testProperties . put ("MCR.LayoutService.TransformerFactoryClass" , "net.sf.saxon.TransformerFactoryImpl" );
193
- testProperties . put ("MCR.ContentTransformer.rules-helper.Class" ,
188
+ MCRConfiguration2 . set ("MCR.URIResolver.ModuleResolver.property" , "org.mycore.common.xml.MCRPropertiesResolver" );
189
+ MCRConfiguration2 . set ("MCR.LayoutService.TransformerFactoryClass" , "net.sf.saxon.TransformerFactoryImpl" );
190
+ MCRConfiguration2 . set ("MCR.ContentTransformer.rules-helper.Class" ,
194
191
"org.mycore.common.content.transformer.MCRXSLTransformer" );
195
- testProperties . put ("MCR.ContentTransformer.rules-helper.TransformerFactoryClass" ,
192
+ MCRConfiguration2 . set ("MCR.ContentTransformer.rules-helper.TransformerFactoryClass" ,
196
193
"net.sf.saxon.TransformerFactoryImpl" );
197
- testProperties . put ("MCR.ContentTransformer.rules-helper.Stylesheet" , "xslt/rules-helper.xsl" );
194
+ MCRConfiguration2 . set ("MCR.ContentTransformer.rules-helper.Stylesheet" , "xslt/rules-helper.xsl" );
198
195
199
- testProperties . put ("MCR.Access.Strategy.Class" , "org.mycore.access.facts.MCRFactsAccessSystem" );
200
- testProperties . put ("MCR.Access.Class" , "org.mycore.access.facts.MCRFactsAccessSystem" );
196
+ MCRConfiguration2 . set ("MCR.Access.Strategy.Class" , "org.mycore.access.facts.MCRFactsAccessSystem" );
197
+ MCRConfiguration2 . set ("MCR.Access.Class" , "org.mycore.access.facts.MCRFactsAccessSystem" );
201
198
202
- testProperties . put ("MCR.Access.RulesURI" , "xslTransform:rules-helper:resource:rules/rules.xml" );
203
- testProperties . put ("MIR.Rules.Solr.Protected.RequestHandler" , "find,select" );
204
- testProperties . put ("MIR.Rules.ClassificationEditor.EditableClasses" ,
199
+ MCRConfiguration2 . set ("MCR.Access.RulesURI" , "xslTransform:rules-helper:resource:rules/rules.xml" );
200
+ MCRConfiguration2 . set ("MIR.Rules.Solr.Protected.RequestHandler" , "find,select" );
201
+ MCRConfiguration2 . set ("MIR.Rules.ClassificationEditor.EditableClasses" ,
205
202
"crossrefTypes,dctermsDCMIType,ddc,derivate_types,diniPublType,diniVersion,identifier,itunes-podcast,marcgt,marcrelator,mcr-roles,mir_access,mir_filetype,mir_genres,mir_institutes,mir_licenses,mir_rights,nameIdentifier,noteTypes,rfc4646,rfc5646,schemaOrg,sdnb,state,typeOfResource,XMetaDissPlusThesisLevel" );
206
203
207
- testProperties . put ("MCR.Access.Facts.Condition.ip-from-institution" ,
204
+ MCRConfiguration2 . set ("MCR.Access.Facts.Condition.ip-from-institution" ,
208
205
"org.mycore.access.facts.condition.fact.MCRIPCondition" );
209
- testProperties . put ("MCR.Access.Facts.Condition.ip-from-institution.IP" , "127.0.0.1/255.255.255.255" );
206
+ MCRConfiguration2 . set ("MCR.Access.Facts.Condition.ip-from-institution.IP" , "127.0.0.1/255.255.255.255" );
210
207
211
- return testProperties ;
212
208
}
213
209
}
0 commit comments