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

Commit 6c256c0

Browse files
Merge pull request #1 from tenpigs267/refacto/jakarta
Refacto/jakarta
2 parents 84a8ebf + 3fcf72c commit 6c256c0

File tree

3 files changed

+53
-20
lines changed

3 files changed

+53
-20
lines changed

pom.xml

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,36 +51,48 @@
5151

5252
<dependencies>
5353
<dependency>
54-
<groupId>com.mysql</groupId>
55-
<artifactId>mysql-connector-j</artifactId>
54+
<groupId>mysql</groupId>
55+
<artifactId>mysql-connector-java</artifactId>
5656
<version>8.0.33</version>
5757
</dependency>
5858
<dependency>
5959
<groupId>org.zeroturnaround</groupId>
6060
<artifactId>zt-zip</artifactId>
61-
<version>1.15</version>
61+
<version>1.16</version>
6262
<type>jar</type>
6363
</dependency>
6464
<dependency>
6565
<groupId>com.sun.mail</groupId>
66-
<artifactId>javax.mail</artifactId>
67-
<version>1.6.2</version>
66+
<artifactId>jakarta.mail</artifactId>
67+
<version>2.0.1</version>
6868
</dependency>
6969
<dependency>
7070
<groupId>org.slf4j</groupId>
7171
<artifactId>slf4j-api</artifactId>
72-
<version>2.0.7</version>
72+
<version>2.0.9</version>
7373
</dependency>
7474
<dependency>
7575
<groupId>org.slf4j</groupId>
7676
<artifactId>slf4j-simple</artifactId>
77-
<version>2.0.7</version>
77+
<version>2.0.9</version>
7878
<scope>test</scope>
7979
</dependency>
8080
<dependency>
8181
<groupId>org.junit.jupiter</groupId>
8282
<artifactId>junit-jupiter-api</artifactId>
83-
<version>5.9.3</version>
83+
<version>5.10.0</version>
84+
<scope>test</scope>
85+
</dependency>
86+
<dependency>
87+
<groupId>org.testcontainers</groupId>
88+
<artifactId>junit-jupiter</artifactId>
89+
<version>1.17.6</version>
90+
<scope>test</scope>
91+
</dependency>
92+
<dependency>
93+
<groupId>org.testcontainers</groupId>
94+
<artifactId>mysql</artifactId>
95+
<version>1.17.6</version>
8496
<scope>test</scope>
8597
</dependency>
8698
</dependencies>

src/main/java/com/smattme/EmailService.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
import org.slf4j.Logger;
44
import org.slf4j.LoggerFactory;
55

6-
import javax.mail.*;
7-
import javax.mail.internet.InternetAddress;
8-
import javax.mail.internet.MimeBodyPart;
9-
import javax.mail.internet.MimeMessage;
10-
import javax.mail.internet.MimeMultipart;
6+
import jakarta.mail.*;
7+
import jakarta.mail.internet.InternetAddress;
8+
import jakarta.mail.internet.MimeBodyPart;
9+
import jakarta.mail.internet.MimeMessage;
10+
import jakarta.mail.internet.MimeMultipart;
1111
import java.io.File;
1212
import java.util.Properties;
1313

src/test/java/com/smattme/MysqlBackup4JIntegrationTest.java

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
import org.junit.jupiter.api.Test;
77
import org.slf4j.Logger;
88
import org.slf4j.LoggerFactory;
9+
import org.testcontainers.containers.MySQLContainer;
10+
import org.testcontainers.junit.jupiter.Container;
11+
import org.testcontainers.junit.jupiter.Testcontainers;
912

1013
import java.io.File;
1114
import java.nio.file.Files;
@@ -22,15 +25,31 @@
2225
*
2326
*/
2427
@Tag("Integration")
28+
@Testcontainers
2529
class MysqlBackup4JIntegrationTest {
2630

2731
private Logger logger = LoggerFactory.getLogger(getClass());
2832
private static final String TEST_DB = "mysqlbackup4j_test";
2933
private static final String RESTORED_DB = "mysqlbackup4j_restored";
3034
private static final String DB_USERNAME = "travis";
31-
private static final String DB_PASSWORD = "";
35+
private static final String DB_PASSWORD = "test";
3236
private static final String DRIVER_CLASS_NAME = "com.mysql.cj.jdbc.Driver";
3337

38+
@Container
39+
private static final MySQLContainer mySQLContainer = new MySQLContainer<>("mysql:8.0.30")
40+
.withDatabaseName(TEST_DB)
41+
.withUsername(DB_USERNAME)
42+
.withPassword(DB_PASSWORD)
43+
.withExposedPorts(3306)
44+
.withInitScript("sample_database.sql");
45+
46+
@Container
47+
private static final MySQLContainer mySQLRestoredContainer = new MySQLContainer<>("mysql:8.0.30")
48+
.withDatabaseName(RESTORED_DB)
49+
.withUsername(DB_USERNAME)
50+
.withPassword(DB_PASSWORD)
51+
.withExposedPorts(3306);
52+
3453
@BeforeAll
3554
static void setUp() {
3655
System.setProperty("org.slf4j.simpleLogger.defaultLogLevel", "debug");
@@ -50,10 +69,12 @@ void givenDBCredentials_whenExportDatabaseAndImportDatabase_thenBackUpAndRestore
5069
properties.setProperty(MysqlExportService.JDBC_DRIVER_NAME, DRIVER_CLASS_NAME);
5170
properties.setProperty(MysqlExportService.ADD_IF_NOT_EXISTS, "true");
5271

53-
5472
properties.setProperty(MysqlExportService.TEMP_DIR, new File("external").getPath());
5573
properties.setProperty(MysqlExportService.SQL_FILE_NAME, "test_output_file_name");
5674

75+
properties.setProperty(MysqlExportService.JDBC_CONNECTION_STRING, mySQLContainer.getJdbcUrl() + "?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC&useSSL=false");
76+
77+
5778
MysqlExportService mysqlExportService = new MysqlExportService(properties);
5879
mysqlExportService.export();
5980

@@ -71,7 +92,7 @@ void givenDBCredentials_whenExportDatabaseAndImportDatabase_thenBackUpAndRestore
7192
String sql = new String(Files.readAllBytes(sqlFile.toPath()));
7293
MysqlImportService res = MysqlImportService.builder()
7394
.setJdbcDriver("com.mysql.cj.jdbc.Driver")
74-
.setDatabase(RESTORED_DB)
95+
.setJdbcConnString(mySQLRestoredContainer.getJdbcUrl())
7596
.setSqlString(sql)
7697
.setUsername(DB_USERNAME)
7798
.setPassword(DB_PASSWORD)
@@ -92,7 +113,7 @@ void givenJDBCConString_whenExportDatabaseAndImportDatabase_thenBackUpAndRestore
92113
properties.setProperty(MysqlExportService.DB_USERNAME, DB_USERNAME);
93114
properties.setProperty(MysqlExportService.DB_PASSWORD, DB_PASSWORD);
94115
properties.setProperty(MysqlExportService.DB_NAME, TEST_DB);
95-
properties.setProperty(MysqlExportService.JDBC_CONNECTION_STRING, "jdbc:mysql://localhost:3306/" + TEST_DB + "?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC&useSSL=false");
116+
properties.setProperty(MysqlExportService.JDBC_CONNECTION_STRING, mySQLContainer.getJdbcUrl() + "?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC&useSSL=false");
96117

97118
properties.setProperty(MysqlExportService.PRESERVE_GENERATED_ZIP, "true");
98119
properties.setProperty(MysqlExportService.PRESERVE_GENERATED_SQL_FILE, "true");
@@ -120,7 +141,7 @@ void givenJDBCConString_whenExportDatabaseAndImportDatabase_thenBackUpAndRestore
120141
String sql = new String(Files.readAllBytes(sqlFile.toPath()));
121142
boolean res = MysqlImportService.builder()
122143
.setSqlString(sql)
123-
.setJdbcConnString("jdbc:mysql://localhost:3306/" + RESTORED_DB + "?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC&useSSL=false")
144+
.setJdbcConnString(mySQLRestoredContainer.getJdbcUrl() + "?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC&useSSL=false")
124145
.setUsername(DB_USERNAME)
125146
.setPassword(DB_PASSWORD)
126147
.setDatabase(RESTORED_DB)
@@ -135,12 +156,12 @@ void givenJDBCConString_whenExportDatabaseAndImportDatabase_thenBackUpAndRestore
135156

136157

137158
private void assertDatabaseBackedUp() throws Exception {
138-
Connection connection = MysqlBaseService.connect(DB_USERNAME, DB_PASSWORD, RESTORED_DB, DRIVER_CLASS_NAME);
159+
Connection connection = MysqlBaseService.connectWithURL(DB_USERNAME, DB_PASSWORD, mySQLRestoredContainer.getJdbcUrl(), DRIVER_CLASS_NAME);
139160
Statement statement = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
140161
statement.execute("SELECT COUNT(1) as total FROM users");
141162
ResultSet resultSet = statement.getResultSet();
142163
resultSet.first();
143164
assertTrue(resultSet.getLong("total") > 0);
144165
}
145166

146-
}
167+
}

0 commit comments

Comments
 (0)