Skip to content
This repository was archived by the owner on Sep 16, 2024. It is now read-only.

Commit 26bc350

Browse files
committed
#434 Upgraded tests to JUnit 5
1 parent d212436 commit 26bc350

File tree

166 files changed

+1230
-581
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

166 files changed

+1230
-581
lines changed

build.gradle

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ repositories {
2121

2222
dependencies {
2323
api 'com.marklogic:ml-javaclient-util:4.2.0-rc1'
24-
api 'jaxen:jaxen:1.2.0'
25-
api 'org.apache.httpcomponents:httpclient:4.5.13'
2624
api 'org.springframework:spring-web:5.3.7'
2725

26+
implementation 'jaxen:jaxen:1.2.0'
27+
implementation 'org.apache.httpcomponents:httpclient:4.5.13'
2828
implementation 'org.jdom:jdom2:2.0.6'
2929

3030
// Forcing httpclient to use this to address https://snyk.io/vuln/SNYK-JAVA-COMMONSCODEC-561518
@@ -37,24 +37,23 @@ dependencies {
3737
implementation "com.flipkart.zjsonpatch:zjsonpatch:0.4.11"
3838

3939
// Required for Java 11
40-
api "javax.xml.bind:jaxb-api:2.3.1"
41-
api "com.sun.xml.bind:jaxb-core:2.3.0.1"
42-
api "com.sun.xml.bind:jaxb-impl:2.3.3"
40+
implementation "javax.xml.bind:jaxb-api:2.3.1"
41+
implementation "com.sun.xml.bind:jaxb-core:2.3.0.1"
42+
implementation "com.sun.xml.bind:jaxb-impl:2.3.3"
4343

4444
// Don't want to include this in the published jar, just the executable jar
4545
compileOnly "com.beust:jcommander:1.78"
4646
compileOnly "ch.qos.logback:logback-classic:1.2.3"
4747

48-
// This uses JUnit 4; we'll soon replace this with marklogic-junit5 and JUnit5
49-
testImplementation 'com.marklogic:ml-junit:3.2.0'
50-
51-
testImplementation "org.springframework:spring-test:5.3.7"
48+
testImplementation "org.junit.jupiter:junit-jupiter:5.7.1"
49+
testImplementation 'org.springframework:spring-test:5.3.7'
5250
testImplementation 'commons-io:commons-io:2.8.0'
51+
testImplementation 'xmlunit:xmlunit:1.6'
5352

5453
// Forcing Spring to use logback for testing instead of commons-logging
5554
testImplementation "ch.qos.logback:logback-classic:1.2.3"
56-
testImplementation group: "org.slf4j", name: "jcl-over-slf4j", version: "1.7.30"
57-
testImplementation group: "org.slf4j", name: "slf4j-api", version: "1.7.30"
55+
testImplementation "org.slf4j:jcl-over-slf4j:1.7.30"
56+
testImplementation "org.slf4j:slf4j-api:1.7.30"
5857
}
5958

6059
// This ensures that Gradle includes in the published jar any non-java files under src/main/java
@@ -83,6 +82,7 @@ publishing {
8382
}
8483

8584
test {
85+
useJUnitPlatform()
8686
testLogging {
8787
events 'started','passed', 'skipped', 'failed'
8888
exceptionFormat 'full'

gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5.1-bin.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-bin.zip

src/test/java/com/marklogic/appdeployer/AbstractAppDeployerTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import com.marklogic.client.ext.modulesloader.impl.DefaultModulesLoader;
88
import com.marklogic.mgmt.AbstractMgmtTest;
99
import com.marklogic.xcc.template.XccTemplate;
10-
import org.junit.Before;
10+
import org.junit.jupiter.api.BeforeEach;
1111

1212
import java.io.File;
1313

@@ -27,7 +27,7 @@ public abstract class AbstractAppDeployerTest extends AbstractMgmtTest {
2727
protected AppDeployer appDeployer;
2828
protected AppConfig appConfig;
2929

30-
@Before
30+
@BeforeEach
3131
public void initialize() {
3232
initializeAppConfig();
3333
}

src/test/java/com/marklogic/appdeployer/DefaultAppConfigFactoryTest.java

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@
55
import com.marklogic.client.ext.SecurityContextType;
66
import com.marklogic.client.ext.modulesloader.impl.PropertiesModuleManager;
77
import com.marklogic.mgmt.util.SimplePropertySource;
8-
import org.junit.Assert;
9-
import org.junit.Test;
8+
import static org.junit.jupiter.api.Assertions.*;
9+
import org.junit.jupiter.api.Test;
1010

1111
import java.io.File;
1212
import java.util.List;
1313
import java.util.Map;
1414
import java.util.Properties;
1515
import java.util.Set;
1616

17-
public class DefaultAppConfigFactoryTest extends Assert {
17+
public class DefaultAppConfigFactoryTest {
1818

1919
private DefaultAppConfigFactory sut;
2020

@@ -84,8 +84,8 @@ public void invalidPropertyValue() {
8484
} catch (IllegalArgumentException ex) {
8585
String message = ex.getMessage();
8686
assertTrue(
87-
"Expected the exception to identify the property name and value; message: " + message,
88-
message.startsWith("Unable to parse value '3' for property 'mlForestsPerHost'")
87+
message.startsWith("Unable to parse value '3' for property 'mlForestsPerHost'"),
88+
"Expected the exception to identify the property name and value; message: " + message
8989
);
9090
}
9191
}
@@ -127,8 +127,8 @@ public void moduleTimestampsPath() {
127127
public void unrecognizedProperties() {
128128
sut = new DefaultAppConfigFactory(new SimplePropertySource("foo.mlHost", "host", "foo.mlUsername", "user"));
129129
AppConfig config = sut.newAppConfig();
130-
assertEquals("Should use default", "localhost", config.getHost());
131-
assertEquals("Should use default", AppConfig.DEFAULT_USERNAME, config.getRestAdminUsername());
130+
assertEquals("localhost", config.getHost(), "Should use default");
131+
assertEquals(AppConfig.DEFAULT_USERNAME, config.getRestAdminUsername(), "Should use default");
132132
}
133133

134134
@Test
@@ -168,8 +168,8 @@ public void cpfDatabaseName() {
168168
sut = new DefaultAppConfigFactory(new SimplePropertySource("mlAppName", "test"));
169169
AppConfig config = sut.newAppConfig();
170170
assertEquals("test-triggers", config.getTriggersDatabaseName());
171-
assertEquals("CPF database should default to the triggers database when not specified",
172-
"test-triggers", config.getCpfDatabaseName());
171+
assertEquals("test-triggers", config.getCpfDatabaseName(),
172+
"CPF database should default to the triggers database when not specified");
173173

174174
sut = new DefaultAppConfigFactory(new SimplePropertySource("mlAppName", "test", "mlCpfDatabaseName", "my-cpf-db"));
175175
config = sut.newAppConfig();
@@ -413,7 +413,7 @@ public void mostProperties() {
413413
assertEquals("appServicesCertPassword", config.getAppServicesCertPassword());
414414
assertEquals("appServicesExternalName", config.getAppServicesExternalName());
415415
assertNotNull(config.getAppServicesSslContext());
416-
assertNotNull("As of 3.15.0, a trust manager must be set in order for SSL to work on >= Java 9", config.getAppServicesTrustManager());
416+
assertNotNull(config.getAppServicesTrustManager(), "As of 3.15.0, a trust manager must be set in order for SSL to work on >= Java 9");
417417
assertEquals(DatabaseClientFactory.SSLHostnameVerifier.ANY, config.getAppServicesSslHostnameVerifier());
418418

419419
assertEquals("my-rest-server", config.getRestServerName());
@@ -437,7 +437,7 @@ public void mostProperties() {
437437

438438
assertNotNull(config.getRestSslContext());
439439
assertNotNull(config.getRestSslHostnameVerifier());
440-
assertNotNull("As of 3.15.0, a trust manager is set so that simple SSL works on >= Java 9", config.getRestTrustManager());
440+
assertNotNull(config.getRestTrustManager(), "As of 3.15.0, a trust manager is set so that simple SSL works on >= Java 9");
441441
assertEquals("my-content-db", config.getContentDatabaseName());
442442
assertEquals("my-test-db", config.getTestContentDatabaseName());
443443
assertEquals("my-modules", config.getModulesDatabaseName());
@@ -561,13 +561,13 @@ public void mlUsernameAndPassword() {
561561
new SimplePropertySource("mlUsername", "customuser", "mlPassword", "custompassword"));
562562
AppConfig config = sut.newAppConfig();
563563

564-
assertEquals("When mlRestAdminUsername is not set, mlUsername should be used", "customuser",
565-
config.getRestAdminUsername());
566-
assertEquals("When mlRestAdminPassword is not set, mlPassword should be used", "custompassword",
567-
config.getRestAdminPassword());
564+
assertEquals("customuser", config.getRestAdminUsername(),
565+
"When mlRestAdminUsername is not set, mlUsername should be used");
566+
assertEquals("custompassword", config.getRestAdminPassword(),
567+
"When mlRestAdminPassword is not set, mlPassword should be used");
568568

569-
assertNull("SSL context should be null by default", config.getRestSslContext());
570-
assertNull("SSL hostname verifier should be null by default", config.getRestSslHostnameVerifier());
569+
assertNull(config.getRestSslContext(), "SSL context should be null by default");
570+
assertNull(config.getRestSslHostnameVerifier(), "SSL hostname verifier should be null by default");
571571
}
572572

573573
@Test
@@ -581,8 +581,8 @@ public void dontModifySetOfDatabasesWithForestsOnOneHostIfItsBeenConfigured() {
581581
assertTrue(set.contains("db2"));
582582

583583
final String message = "If the user has configured the set of databases, then the default schema and trigger databases names should not be added automatically";
584-
assertFalse(message, set.contains("example-triggers"));
585-
assertFalse(message, set.contains("example-schemas"));
584+
assertFalse(set.contains("example-triggers"), message);
585+
assertFalse(set.contains("example-schemas"), message);
586586
}
587587

588588
@Test

src/test/java/com/marklogic/appdeployer/MergeResourcesWhileDeployingTest.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,21 @@
2121
import com.marklogic.mgmt.resource.security.PrivilegeManager;
2222
import com.marklogic.mgmt.resource.security.RoleManager;
2323
import com.marklogic.mgmt.resource.security.UserManager;
24-
import org.junit.After;
25-
import org.junit.Before;
26-
import org.junit.Test;
24+
import org.junit.jupiter.api.AfterEach;
25+
import org.junit.jupiter.api.BeforeEach;
26+
import org.junit.jupiter.api.Test;
2727

2828
import java.io.File;
2929
import java.util.ArrayList;
3030
import java.util.List;
3131

32+
import static org.junit.jupiter.api.Assertions.*;
33+
3234
public class MergeResourcesWhileDeployingTest extends AbstractAppDeployerTest {
3335

3436
private ResourceMapper resourceMapper;
3537

36-
@Before
38+
@BeforeEach
3739
public void setup() {
3840
List<ConfigDir> list = new ArrayList<>();
3941
list.add(new ConfigDir(new File("src/test/resources/sample-app/multiple-config-paths/path1")));
@@ -43,7 +45,7 @@ public void setup() {
4345
resourceMapper = new DefaultResourceMapper(new API(manageClient));
4446
}
4547

46-
@After
48+
@AfterEach
4749
public void teardown() {
4850
undeploySampleApp();
4951
}
@@ -56,7 +58,7 @@ public void users() {
5658
UserManager mgr = new UserManager(manageClient);
5759
User user = resourceMapper.readResource(mgr.getAsJson("sample-app-jane"), User.class);
5860
assertEquals(2, user.getRole().size());
59-
assertEquals("The role from the first path should be first", "rest-reader", user.getRole().get(0));
61+
assertEquals("rest-reader", user.getRole().get(0), "The role from the first path should be first");
6062
assertEquals("manage-user", user.getRole().get(1));
6163
}
6264

@@ -138,8 +140,8 @@ private void deployMultipleDatabasesNeededMergingAndVerify() {
138140
assertEquals(2, db.getRangeElementIndex().size());
139141
assertEquals("id", db.getRangeElementIndex().get(0).getLocalname());
140142
assertEquals("otherId", db.getRangeElementIndex().get(1).getLocalname());
141-
assertTrue("The file in the second path should override single-value properties from the " +
142-
"file in the first path", db.getTripleIndex());
143+
assertTrue(db.getTripleIndex(), "The file in the second path should override single-value properties from the " +
144+
"file in the first path");
143145
assertEquals("sample-app-schema-database", db.getSchemaDatabase());
144146
assertEquals("sample-app-triggers-database", db.getTriggersDatabase());
145147

src/test/java/com/marklogic/appdeployer/PopulateCustomTokensTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
package com.marklogic.appdeployer;
22

33
import com.marklogic.appdeployer.util.SimplePropertiesSource;
4-
import org.junit.Assert;
5-
import org.junit.Before;
6-
import org.junit.Test;
4+
import static org.junit.jupiter.api.Assertions.*;
5+
import org.junit.jupiter.api.BeforeEach;
6+
import org.junit.jupiter.api.Test;
77

88
import java.util.Map;
99
import java.util.Properties;
1010

11-
public class PopulateCustomTokensTest extends Assert {
11+
public class PopulateCustomTokensTest {
1212

1313
private AppConfig appConfig;
1414
private Properties props;
1515

16-
@Before
16+
@BeforeEach
1717
public void setup() {
1818
appConfig = new AppConfig();
1919

src/test/java/com/marklogic/appdeployer/command/AbstractIncrementalDeployTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@
22

33
import com.marklogic.appdeployer.AbstractAppDeployerTest;
44
import com.marklogic.mgmt.ManageClient;
5-
import org.junit.Before;
5+
import org.junit.jupiter.api.BeforeEach;
66

77
public abstract class AbstractIncrementalDeployTest extends AbstractAppDeployerTest {
88

99
protected ManageClient originalManageClient;
1010

11-
@Before
11+
@BeforeEach
1212
public void setupIncrementalDeployTest() {
1313
appConfig.setIncrementalDeploy(true);
1414
this.originalManageClient = this.manageClient;
1515
deleteResourceTimestampsFile();
1616
}
17-
17+
1818
public void deleteResourceTimestampsFile() {
1919
new ResourceFileManagerImpl().deletePropertiesFile();
2020
}

src/test/java/com/marklogic/appdeployer/command/AbstractManageResourceTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22

33
import com.marklogic.appdeployer.AbstractAppDeployerTest;
44
import com.marklogic.mgmt.resource.ResourceManager;
5-
import org.junit.Test;
5+
import org.junit.jupiter.api.Test;
6+
7+
import static org.junit.jupiter.api.Assertions.assertFalse;
8+
import static org.junit.jupiter.api.Assertions.assertTrue;
69

710
/**
811
* Provides a basic create-then-delete test for testing any implementation of ResourceManager.

src/test/java/com/marklogic/appdeployer/command/PayloadPropertiesTest.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@
44
import com.marklogic.appdeployer.command.databases.DeployOtherDatabasesCommand;
55
import com.marklogic.mgmt.resource.databases.DatabaseManager;
66
import com.marklogic.rest.util.Fragment;
7-
import org.junit.After;
8-
import org.junit.Test;
7+
import org.junit.jupiter.api.AfterEach;
8+
import org.junit.jupiter.api.Test;
99

1010
import java.io.File;
1111

12+
import static org.junit.jupiter.api.Assertions.*;
13+
1214
public class PayloadPropertiesTest extends AbstractAppDeployerTest {
1315

14-
@After
16+
@AfterEach
1517
public void teardown() {
1618
undeploySampleApp();
1719
}

src/test/java/com/marklogic/appdeployer/command/ReplaceTokensTest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@
99
import com.marklogic.client.ext.modulesloader.impl.DefaultModulesLoader;
1010
import com.marklogic.client.io.BytesHandle;
1111
import com.marklogic.client.io.StringHandle;
12-
import org.junit.Test;
12+
import org.junit.jupiter.api.Test;
1313

1414
import java.io.File;
1515
import java.util.Arrays;
1616
import java.util.Properties;
1717

18+
import static org.junit.jupiter.api.Assertions.assertTrue;
19+
1820
public class ReplaceTokensTest extends AbstractAppDeployerTest {
1921

2022
@Test
@@ -41,7 +43,7 @@ public void test() {
4143
DatabaseClient modulesClient = appConfig.newAppServicesDatabaseClient(appConfig.getModulesDatabaseName());
4244
try {
4345
String moduleText = new String(modulesClient.newDocumentManager().read("/hello.xqy", new BytesHandle()).get());
44-
assertTrue("Did not find replaced text in module: " + moduleText, moduleText.contains("replaced!"));
46+
assertTrue(moduleText.contains("replaced!"), "Did not find replaced text in module: " + moduleText);
4547
} finally {
4648
modulesClient.release();
4749
undeploySampleApp();

0 commit comments

Comments
 (0)