Skip to content

Commit c03d3b9

Browse files
committed
MCR-3393 migrate unit tests to JUnit 5
1 parent 5aadfd2 commit c03d3b9

17 files changed

+286
-194
lines changed

mir-module/pom.xml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,6 @@
152152
<groupId>jakarta.ws.rs</groupId>
153153
<artifactId>jakarta.ws.rs-api</artifactId>
154154
</dependency>
155-
<dependency>
156-
<groupId>junit</groupId>
157-
<artifactId>junit</artifactId>
158-
</dependency>
159155
<dependency>
160156
<groupId>net.sf.saxon</groupId>
161157
<artifactId>Saxon-HE</artifactId>
@@ -287,5 +283,10 @@
287283
<artifactId>pica2mods-xslt</artifactId>
288284
<scope>runtime</scope>
289285
</dependency>
286+
<dependency>
287+
<groupId>org.junit.jupiter</groupId>
288+
<artifactId>junit-jupiter-api</artifactId>
289+
<scope>test</scope>
290+
</dependency>
290291
</dependencies>
291292
</project>

mir-module/src/test/java/org/mycore/mir/acl/MIRACLTest.java

Lines changed: 48 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,21 @@
1818

1919
package org.mycore.mir.acl;
2020

21+
import static org.junit.jupiter.api.Assertions.assertFalse;
22+
import static org.junit.jupiter.api.Assertions.assertTrue;
23+
2124
import java.util.Arrays;
2225
import java.util.List;
23-
import java.util.Map;
2426
import java.util.stream.Collectors;
2527
import java.util.stream.Stream;
2628

27-
28-
import org.junit.Assert;
29+
import org.junit.jupiter.api.BeforeEach;
2930
import org.mycore.access.facts.MCRFactsAccessSystem;
3031
import org.mycore.access.facts.fact.MCRStringFact;
3132
import org.mycore.access.facts.model.MCRFact;
32-
import org.mycore.common.MCRStoreTestCase;
3333
import org.mycore.common.config.MCRConfiguration2;
3434

35-
public class MIRACLTest extends MCRStoreTestCase {
35+
public abstract class MIRACLTest {
3636

3737
MCRFactsAccessSystem accessSystem;
3838

@@ -44,9 +44,9 @@ public void disableDebug() {
4444
//Configurator.setLevel(LogManager.getLogger(MCRFactsAccessSystem.class).getName(), Level.INFO);
4545
}
4646

47-
@Override
48-
public void setUp() throws Exception {
49-
super.setUp();
47+
@BeforeEach
48+
public void setUp() {
49+
setTestProperties();
5050
accessSystem = MCRConfiguration2.getInstanceOfOrThrow(MCRFactsAccessSystem.class, "MCR.Access.Class");
5151
}
5252

@@ -55,11 +55,10 @@ protected void checkWebpage(String webpageURL, boolean shouldBeAbleToRead, Strin
5555
Arrays.stream(userRole).map(role -> new MCRStringFact("role", role)).collect(Collectors.toList()));
5656

5757
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);
6059
} 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);
6362
}
6463
}
6564

@@ -68,9 +67,9 @@ protected void checkReadId(String id, boolean shouldBeAbleToRead, String... user
6867
Arrays.stream(userRole).map(role -> new MCRStringFact("role", role)).collect(Collectors.toList()));
6968

7069
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);
7271
} 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);
7473
}
7574
}
7675

@@ -98,9 +97,9 @@ public void testPermission(String user, String action, boolean shouldBeAbleTo, S
9897
boolean hasPermission = accessSystem.checkPermission(null, action, facts);
9998

10099
if (shouldBeAbleTo) {
101-
Assert.assertTrue(user + " should be able to " + action, hasPermission);
100+
assertTrue(hasPermission, user + " should be able to " + action);
102101
} else {
103-
Assert.assertFalse(user + " should not be able to " + action, hasPermission);
102+
assertFalse(hasPermission, user + " should not be able to " + action);
104103
}
105104
}
106105

@@ -130,9 +129,9 @@ public void testObject(String user, String creator, String status, String id, bo
130129
boolean hasPermission = accessSystem.checkPermission(id, action, facts);
131130

132131
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);
134133
} 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);
136135
}
137136
}
138137

@@ -149,65 +148,62 @@ public void testReadWriteObject(String user, String creator, String status, Stri
149148
testReadWriteObject(user, creator, status, id, shouldBeAbleToReadWrite, read, role, embargo, false, false);
150149
}
151150

152-
@Override
153-
protected Map<String, String> getTestProperties() {
154-
Map<String, String> testProperties = super.getTestProperties();
151+
private void setTestProperties() {
155152

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");
158155

159-
testProperties.put("MCR.Access.Facts.Condition.and",
156+
MCRConfiguration2.set("MCR.Access.Facts.Condition.and",
160157
"org.mycore.access.facts.condition.combined.MCRAndCondition");
161-
testProperties.put("MCR.Access.Facts.Condition.or",
158+
MCRConfiguration2.set("MCR.Access.Facts.Condition.or",
162159
"org.mycore.access.facts.condition.combined.MCROrCondition");
163-
testProperties.put("MCR.Access.Facts.Condition.not",
160+
MCRConfiguration2.set("MCR.Access.Facts.Condition.not",
164161
"org.mycore.access.facts.condition.combined.MCRNotCondition");
165-
testProperties.put("MCR.Access.Facts.Condition.id",
162+
MCRConfiguration2.set("MCR.Access.Facts.Condition.id",
166163
"org.mycore.access.facts.condition.fact.MCRStringCondition");
167-
testProperties.put("MCR.Access.Facts.Condition.target",
164+
MCRConfiguration2.set("MCR.Access.Facts.Condition.target",
168165
"org.mycore.access.facts.condition.fact.MCRStringCondition");
169-
testProperties.put("MCR.Access.Facts.Condition.action",
166+
MCRConfiguration2.set("MCR.Access.Facts.Condition.action",
170167
"org.mycore.access.facts.condition.fact.MCRStringCondition");
171-
testProperties.put("MCR.Access.Facts.Condition.user",
168+
MCRConfiguration2.set("MCR.Access.Facts.Condition.user",
172169
"org.mycore.access.facts.condition.fact.MCRUserCondition");
173-
testProperties.put("MCR.Access.Facts.Condition.role",
170+
MCRConfiguration2.set("MCR.Access.Facts.Condition.role",
174171
"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",
177174
"org.mycore.access.facts.condition.fact.MCRStateCondition");
178-
testProperties.put("MCR.Access.Facts.Condition.createdby",
175+
MCRConfiguration2.set("MCR.Access.Facts.Condition.createdby",
179176
"org.mycore.access.facts.condition.fact.MCRCreatedByCondition");
180-
testProperties.put("MCR.Access.Facts.Condition.regex",
177+
MCRConfiguration2.set("MCR.Access.Facts.Condition.regex",
181178
"org.mycore.access.facts.condition.fact.MCRRegExCondition");
182-
testProperties.put("MCR.Access.Facts.Condition.category",
179+
MCRConfiguration2.set("MCR.Access.Facts.Condition.category",
183180
"org.mycore.access.facts.condition.fact.MCRCategoryCondition");
184-
testProperties.put("MCR.Access.Facts.Condition.collection",
181+
MCRConfiguration2.set("MCR.Access.Facts.Condition.collection",
185182
"org.mycore.mods.access.facts.condition.MCRMODSCollectionCondition");
186-
testProperties.put("MCR.Access.Facts.Condition.genre",
183+
MCRConfiguration2.set("MCR.Access.Facts.Condition.genre",
187184
"org.mycore.mods.access.facts.condition.MCRMODSGenreCondition");
188-
testProperties.put("MCR.Access.Facts.Condition.embargo",
185+
MCRConfiguration2.set("MCR.Access.Facts.Condition.embargo",
189186
"org.mycore.mods.access.facts.condition.MCRMODSEmbargoCondition");
190187

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",
194191
"org.mycore.common.content.transformer.MCRXSLTransformer");
195-
testProperties.put("MCR.ContentTransformer.rules-helper.TransformerFactoryClass",
192+
MCRConfiguration2.set("MCR.ContentTransformer.rules-helper.TransformerFactoryClass",
196193
"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");
198195

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");
201198

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",
205202
"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");
206203

207-
testProperties.put("MCR.Access.Facts.Condition.ip-from-institution",
204+
MCRConfiguration2.set("MCR.Access.Facts.Condition.ip-from-institution",
208205
"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");
210207

211-
return testProperties;
212208
}
213209
}

mir-module/src/test/java/org/mycore/mir/acl/MIRCreateACLTest.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,24 @@
1818

1919
package org.mycore.mir.acl;
2020

21-
import org.junit.Test;
21+
import org.junit.jupiter.api.BeforeEach;
22+
import org.junit.jupiter.api.Test;
23+
import org.junit.jupiter.api.extension.ExtendWith;
24+
import org.mycore.test.MCRJPAExtension;
25+
import org.mycore.test.MCRMetadataExtension;
26+
import org.mycore.test.MyCoReTest;
2227

28+
29+
@MyCoReTest
30+
@ExtendWith(MCRJPAExtension.class)
31+
@ExtendWith(MCRMetadataExtension.class)
2332
public class MIRCreateACLTest extends MIRACLTest {
2433

34+
@Override
35+
@BeforeEach
36+
public void setUp() {
37+
super.setUp();
38+
}
2539

2640
@Test
2741
public void testCreateGuest() {

mir-module/src/test/java/org/mycore/mir/acl/MIRDeleteACLTest.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,24 @@
1818

1919
package org.mycore.mir.acl;
2020

21-
import org.junit.Test;
22-
21+
import org.junit.jupiter.api.BeforeEach;
22+
import org.junit.jupiter.api.Test;
23+
import org.junit.jupiter.api.extension.ExtendWith;
24+
import org.mycore.test.MCRJPAExtension;
25+
import org.mycore.test.MCRMetadataExtension;
26+
import org.mycore.test.MyCoReTest;
27+
28+
@MyCoReTest
29+
@ExtendWith(MCRJPAExtension.class)
30+
@ExtendWith(MCRMetadataExtension.class)
2331
public class MIRDeleteACLTest extends MIRACLTest{
2432

33+
@Override
34+
@BeforeEach
35+
public void setUp() {
36+
super.setUp();
37+
}
38+
2539
@Test
2640
public void testDeleteObjectGuest() {
2741
// status published

mir-module/src/test/java/org/mycore/mir/acl/MIREditorACLTest.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,27 @@
1818

1919
package org.mycore.mir.acl;
2020

21-
import org.junit.Test;
21+
import org.junit.jupiter.api.BeforeEach;
22+
import org.junit.jupiter.api.Test;
23+
import org.junit.jupiter.api.extension.ExtendWith;
24+
import org.mycore.test.MCRJPAExtension;
25+
import org.mycore.test.MCRMetadataExtension;
26+
import org.mycore.test.MyCoReTest;
2227

2328
/**
2429
* Checks if a user can open a specific editor
2530
*/
31+
@MyCoReTest
32+
@ExtendWith(MCRJPAExtension.class)
33+
@ExtendWith(MCRMetadataExtension.class)
2634
public class MIREditorACLTest extends MIRACLTest {
2735

36+
@Override
37+
@BeforeEach
38+
public void setUp() {
39+
super.setUp();
40+
}
41+
2842
@Test
2943
public void testEditorGuest() {
3044
checkWebpage( "/editor/editor-dynamic.xed", false, "");

mir-module/src/test/java/org/mycore/mir/acl/MIRReadObjectACLTest.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,24 @@
1818

1919
package org.mycore.mir.acl;
2020

21-
import org.junit.Test;
22-
21+
import org.junit.jupiter.api.BeforeEach;
22+
import org.junit.jupiter.api.Test;
23+
import org.junit.jupiter.api.extension.ExtendWith;
24+
import org.mycore.test.MCRJPAExtension;
25+
import org.mycore.test.MCRMetadataExtension;
26+
import org.mycore.test.MyCoReTest;
27+
28+
@MyCoReTest
29+
@ExtendWith(MCRJPAExtension.class)
30+
@ExtendWith(MCRMetadataExtension.class)
2331
public class MIRReadObjectACLTest extends MIRACLTest {
2432

33+
@Override
34+
@BeforeEach
35+
public void setUp() {
36+
super.setUp();
37+
}
38+
2539
@Test
2640
public void testReadObjectGuest() {
2741
// status published

mir-module/src/test/java/org/mycore/mir/acl/MIRSearchACLTest.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,27 @@
1818

1919
package org.mycore.mir.acl;
2020

21-
import org.junit.Test;
21+
import org.junit.jupiter.api.BeforeEach;
22+
import org.junit.jupiter.api.Test;
23+
import org.junit.jupiter.api.extension.ExtendWith;
24+
import org.mycore.test.MCRJPAExtension;
25+
import org.mycore.test.MCRMetadataExtension;
26+
import org.mycore.test.MyCoReTest;
2227

2328
/**
2429
* Check if a specific user can open the right search form and use solr-request handler
2530
*/
31+
@MyCoReTest
32+
@ExtendWith(MCRJPAExtension.class)
33+
@ExtendWith(MCRMetadataExtension.class)
2634
public class MIRSearchACLTest extends MIRACLTest {
2735

36+
@Override
37+
@BeforeEach
38+
public void setUp() {
39+
super.setUp();
40+
}
41+
2842
@Test
2943
public void testSearchGuest() {
3044
checkWebpage( "/content/search/simple.xed", true, "");

mir-module/src/test/java/org/mycore/mir/acl/MIRWriteObjectACLTest.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,23 @@
1818

1919
package org.mycore.mir.acl;
2020

21-
import org.junit.Test;
22-
21+
import org.junit.jupiter.api.BeforeEach;
22+
import org.junit.jupiter.api.Test;
23+
import org.junit.jupiter.api.extension.ExtendWith;
24+
import org.mycore.test.MCRJPAExtension;
25+
import org.mycore.test.MCRMetadataExtension;
26+
import org.mycore.test.MyCoReTest;
27+
28+
@MyCoReTest
29+
@ExtendWith(MCRJPAExtension.class)
30+
@ExtendWith(MCRMetadataExtension.class)
2331
public class MIRWriteObjectACLTest extends MIRACLTest {
2432

33+
@Override
34+
@BeforeEach
35+
public void setUp() {
36+
super.setUp();
37+
}
2538

2639
@Test
2740
public void testWriteObjectGuest() {

0 commit comments

Comments
 (0)