Integration tests added for adding data to database following block break trigger and all tests passing.
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
4
README.md
Normal file
4
README.md
Normal file
@@ -0,0 +1,4 @@
|
||||
# Build from windows command line:
|
||||
## 1. cd /path/to/project
|
||||
## 2. gradlew.bat build
|
||||
## 3. find .jar file in build/libs
|
||||
@@ -1,89 +0,0 @@
|
||||
plugins {
|
||||
id 'eclipse'
|
||||
id 'maven-publish'
|
||||
id 'net.minecraftforge.gradle' version '5.1.+'
|
||||
}
|
||||
|
||||
version = '1.0'
|
||||
group = 'com.example.playerstats'
|
||||
archivesBaseName = 'playerstats'
|
||||
|
||||
java.toolchain.languageVersion = JavaLanguageVersion.of(17)
|
||||
|
||||
minecraft {
|
||||
mappings channel: 'official', version: '1.18.2'
|
||||
|
||||
runs {
|
||||
client {
|
||||
workingDirectory project.file('run')
|
||||
property 'forge.logging.markers', 'REGISTRIES'
|
||||
property 'forge.logging.console.level', 'debug'
|
||||
mods {
|
||||
playerstats {
|
||||
source sourceSets.main
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
server {
|
||||
workingDirectory project.file('run')
|
||||
property 'forge.logging.markers', 'REGISTRIES'
|
||||
property 'forge.logging.console.level', 'debug'
|
||||
mods {
|
||||
playerstats {
|
||||
source sourceSets.main
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Add test configuration
|
||||
gameTestServer {
|
||||
workingDirectory project.file('run')
|
||||
property 'forge.logging.markers', 'REGISTRIES'
|
||||
property 'forge.logging.console.level', 'debug'
|
||||
mods {
|
||||
playerstats {
|
||||
source sourceSets.main
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
minecraft 'net.minecraftforge:forge:1.18.2-40.1.0'
|
||||
implementation 'mysql:mysql-connector-java:8.0.27'
|
||||
|
||||
// Test dependencies
|
||||
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2'
|
||||
testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.8.2'
|
||||
testImplementation 'org.mockito:mockito-core:4.3.1'
|
||||
testImplementation 'org.mockito:mockito-junit-jupiter:4.3.1'
|
||||
testImplementation 'org.hamcrest:hamcrest:2.2'
|
||||
}
|
||||
|
||||
test {
|
||||
useJUnitPlatform()
|
||||
testLogging {
|
||||
events "passed", "skipped", "failed"
|
||||
}
|
||||
}
|
||||
|
||||
jar {
|
||||
manifest {
|
||||
attributes([
|
||||
"Specification-Title": "playerstats",
|
||||
"Specification-Vendor": "examplemodsareus",
|
||||
"Specification-Version": "1",
|
||||
"Implementation-Title": project.name,
|
||||
"Implementation-Version": project.jar.archiveVersion,
|
||||
"Implementation-Vendor" :"examplemodsareus",
|
||||
"Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ")
|
||||
])
|
||||
}
|
||||
}
|
||||
|
||||
// Add repositories if needed
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
@@ -3,7 +3,7 @@ Arguments: '--in-jar, C:\Users\edwar\OneDrive\Documents\Minecraft\minecraft_mod_
|
||||
Classpath:
|
||||
- C:\Users\edwar\.gradle\caches\forge_gradle\maven_downloader\net\md-5\SpecialSource\1.11.0\SpecialSource-1.11.0-shaded.jar
|
||||
- C:\Users\edwar\.gradle\caches\modules-2\files-2.1\mysql\mysql-connector-java\8.0.27\f1da9f10a3de6348725a413304aab6d0aa04f923\mysql-connector-java-8.0.27.jar
|
||||
- C:\Users\edwar\.gradle\caches\forge_gradle\minecraft_user_repo\net\minecraftforge\forge\1.18.2-40.1.0_mapped_official_1.18.2\forge-1.18.2-40.1.0_mapped_official_1.18.2.jar
|
||||
- C:\Users\edwar\.gradle\caches\forge_gradle\minecraft_user_repo\net\minecraftforge\forge\1.18.2-40.1.0_mapped_official_1.18.2\forge-1.18.2-40.1.0_mapped_official_1.18.2-recomp.jar
|
||||
- C:\Users\edwar\.gradle\caches\modules-2\files-2.1\com.google.protobuf\protobuf-java\3.11.4\7ec0925cc3aef0335bbc7d57edfd42b0f86f8267\protobuf-java-3.11.4.jar
|
||||
- C:\Users\edwar\.gradle\caches\forge_gradle\minecraft_repo\versions\1.18.2\client-extra.jar
|
||||
- C:\Users\edwar\.gradle\caches\modules-2\files-2.1\net.minecraftforge\fmlloader\1.18.2-40.1.0\842aac12c6cbd1b6dc9dd9ae4e98038e70a2b832\fmlloader-1.18.2-40.1.0.jar
|
||||
|
||||
Binary file not shown.
@@ -41,7 +41,7 @@
|
||||
</td>
|
||||
<td>
|
||||
<div class="infoBox" id="duration">
|
||||
<div class="counter">0.735s</div>
|
||||
<div class="counter">0.756s</div>
|
||||
<p>duration</p>
|
||||
</div>
|
||||
</td>
|
||||
@@ -76,7 +76,7 @@
|
||||
</thead>
|
||||
<tr>
|
||||
<td class="success">testRecordStat()</td>
|
||||
<td class="success">0.735s</td>
|
||||
<td class="success">0.756s</td>
|
||||
<td class="success">passed</td>
|
||||
</tr>
|
||||
</table>
|
||||
@@ -89,7 +89,7 @@
|
||||
<input id="line-wrapping-toggle" type="checkbox" autocomplete="off"/>
|
||||
</label>
|
||||
</div>Generated by
|
||||
<a href="http://www.gradle.org">Gradle 7.6.1</a> at 3 Dec 2024, 16:06:46</p>
|
||||
<a href="http://www.gradle.org">Gradle 7.6.1</a> at 4 Dec 2024, 09:29:41</p>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
<tr>
|
||||
<td>
|
||||
<div class="infoBox" id="tests">
|
||||
<div class="counter">1</div>
|
||||
<div class="counter">3</div>
|
||||
<p>tests</p>
|
||||
</div>
|
||||
</td>
|
||||
@@ -38,7 +38,7 @@
|
||||
</td>
|
||||
<td>
|
||||
<div class="infoBox" id="duration">
|
||||
<div class="counter">0.735s</div>
|
||||
<div class="counter">0.947s</div>
|
||||
<p>duration</p>
|
||||
</div>
|
||||
</td>
|
||||
@@ -82,10 +82,10 @@
|
||||
<td class="success">
|
||||
<a href="packages/minecraft_mod_player_statistics.src.test.java.html">minecraft_mod_player_statistics.src.test.java</a>
|
||||
</td>
|
||||
<td>1</td>
|
||||
<td>3</td>
|
||||
<td>0</td>
|
||||
<td>0</td>
|
||||
<td>0.735s</td>
|
||||
<td>0.947s</td>
|
||||
<td class="success">100%</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
@@ -107,12 +107,22 @@
|
||||
<tbody>
|
||||
<tr>
|
||||
<td class="success">
|
||||
<a href="classes/minecraft_mod_player_statistics.src.test.java.DatabaseManagerIntegrationTest.html">minecraft_mod_player_statistics.src.test.java.DatabaseManagerIntegrationTest</a>
|
||||
</td>
|
||||
<td>2</td>
|
||||
<td>0</td>
|
||||
<td>0</td>
|
||||
<td>0.191s</td>
|
||||
<td class="success">100%</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="success">
|
||||
<a href="classes/minecraft_mod_player_statistics.src.test.java.DatabaseManagerTest.html">minecraft_mod_player_statistics.src.test.java.DatabaseManagerTest</a>
|
||||
</td>
|
||||
<td>1</td>
|
||||
<td>0</td>
|
||||
<td>0</td>
|
||||
<td>0.735s</td>
|
||||
<td>0.756s</td>
|
||||
<td class="success">100%</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
@@ -126,7 +136,7 @@
|
||||
<input id="line-wrapping-toggle" type="checkbox" autocomplete="off"/>
|
||||
</label>
|
||||
</div>Generated by
|
||||
<a href="http://www.gradle.org">Gradle 7.6.1</a> at 3 Dec 2024, 16:06:46</p>
|
||||
<a href="http://www.gradle.org">Gradle 7.6.1</a> at 4 Dec 2024, 09:29:41</p>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
<tr>
|
||||
<td>
|
||||
<div class="infoBox" id="tests">
|
||||
<div class="counter">1</div>
|
||||
<div class="counter">3</div>
|
||||
<p>tests</p>
|
||||
</div>
|
||||
</td>
|
||||
@@ -40,7 +40,7 @@
|
||||
</td>
|
||||
<td>
|
||||
<div class="infoBox" id="duration">
|
||||
<div class="counter">0.735s</div>
|
||||
<div class="counter">0.947s</div>
|
||||
<p>duration</p>
|
||||
</div>
|
||||
</td>
|
||||
@@ -78,12 +78,22 @@
|
||||
</thread>
|
||||
<tr>
|
||||
<td class="success">
|
||||
<a href="../classes/minecraft_mod_player_statistics.src.test.java.DatabaseManagerIntegrationTest.html">DatabaseManagerIntegrationTest</a>
|
||||
</td>
|
||||
<td>2</td>
|
||||
<td>0</td>
|
||||
<td>0</td>
|
||||
<td>0.191s</td>
|
||||
<td class="success">100%</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="success">
|
||||
<a href="../classes/minecraft_mod_player_statistics.src.test.java.DatabaseManagerTest.html">DatabaseManagerTest</a>
|
||||
</td>
|
||||
<td>1</td>
|
||||
<td>0</td>
|
||||
<td>0</td>
|
||||
<td>0.735s</td>
|
||||
<td>0.756s</td>
|
||||
<td class="success">100%</td>
|
||||
</tr>
|
||||
</table>
|
||||
@@ -96,7 +106,7 @@
|
||||
<input id="line-wrapping-toggle" type="checkbox" autocomplete="off"/>
|
||||
</label>
|
||||
</div>Generated by
|
||||
<a href="http://www.gradle.org">Gradle 7.6.1</a> at 3 Dec 2024, 16:06:46</p>
|
||||
<a href="http://www.gradle.org">Gradle 7.6.1</a> at 4 Dec 2024, 09:29:41</p>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<testsuite name="minecraft_mod_player_statistics.src.test.java.DatabaseManagerTest" tests="1" skipped="0" failures="0" errors="0" timestamp="2024-12-03T16:06:45" hostname="DESKTOP-DS0UFJ8" time="0.735">
|
||||
<testsuite name="minecraft_mod_player_statistics.src.test.java.DatabaseManagerTest" tests="1" skipped="0" failures="0" errors="0" timestamp="2024-12-04T09:29:41" hostname="DESKTOP-DS0UFJ8" time="0.756">
|
||||
<properties/>
|
||||
<testcase name="testRecordStat()" classname="minecraft_mod_player_statistics.src.test.java.DatabaseManagerTest" time="0.735"/>
|
||||
<testcase name="testRecordStat()" classname="minecraft_mod_player_statistics.src.test.java.DatabaseManagerTest" time="0.756"/>
|
||||
<system-out><![CDATA[]]></system-out>
|
||||
<system-err><![CDATA[]]></system-err>
|
||||
</testsuite>
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -5,5 +5,5 @@ Specification-Version: 1
|
||||
Implementation-Title: minecraft_mod_player_statistics
|
||||
Implementation-Version: 1.0
|
||||
Implementation-Vendor: examplemodsareus
|
||||
Implementation-Timestamp: 2024-12-03T16:06:41+0000
|
||||
Implementation-Timestamp: 2024-12-04T09:29:32+0000
|
||||
|
||||
|
||||
@@ -14,9 +14,9 @@ import java.util.logging.Logger;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class DatabaseManager {
|
||||
private static final String DB_URL = "jdbc:mysql://localhost:3306/minecraft_stats";
|
||||
private static final String DB_URL = "jdbc:mysql://localhost:3306/partsltd_dev";
|
||||
private static final String DB_USER = "root";
|
||||
private static final String DB_PASS = "password";
|
||||
private static final String DB_PASS = System.getenv("DB_PASSWORD"); // "password";
|
||||
private static final Logger LOGGER = Logger.getLogger(DatabaseManager.class.getName());
|
||||
|
||||
public Connection getConnection() throws SQLException {
|
||||
|
||||
92
src/test/java/DatabaseManagerIntegrationTest.java
Normal file
92
src/test/java/DatabaseManagerIntegrationTest.java
Normal file
@@ -0,0 +1,92 @@
|
||||
package minecraft_mod_player_statistics.src.test.java;
|
||||
|
||||
import minecraft_mod_player_statistics.src.main.java.DatabaseManager;
|
||||
import org.junit.jupiter.api.*;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.UUID;
|
||||
|
||||
public class DatabaseManagerIntegrationTest {
|
||||
private static DatabaseManager dbManager;
|
||||
private static final UUID TEST_PLAYER_UUID = UUID.randomUUID();
|
||||
private static final String TEST_STAT_TYPE = "integration_test_stat";
|
||||
private static final String TEST_BLOCK_ID = "minecraft:test_block";
|
||||
private static final int TEST_VALUE = 42;
|
||||
|
||||
@BeforeAll
|
||||
static void setUp() {
|
||||
dbManager = new DatabaseManager();
|
||||
// Initialize database schema
|
||||
dbManager.initializeDatabase();
|
||||
}
|
||||
|
||||
@BeforeEach
|
||||
void cleanupTestData() throws SQLException {
|
||||
// Clean up any test data before each test
|
||||
try (Connection conn = dbManager.getConnection();
|
||||
PreparedStatement stmt = conn.prepareStatement(
|
||||
"DELETE FROM player_stats WHERE stat_type = ?")) {
|
||||
stmt.setString(1, TEST_STAT_TYPE);
|
||||
stmt.executeUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDatabaseConnection() throws SQLException {
|
||||
// Test basic connection
|
||||
try (Connection conn = dbManager.getConnection()) {
|
||||
Assertions.assertTrue(conn.isValid(5));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testRecordAndRetrieveStat() throws SQLException {
|
||||
// Record a test statistic
|
||||
dbManager.recordStat(TEST_PLAYER_UUID, TEST_STAT_TYPE, TEST_VALUE, TEST_BLOCK_ID);
|
||||
|
||||
// Verify the recorded data
|
||||
try (Connection conn = dbManager.getConnection();
|
||||
PreparedStatement stmt = conn.prepareStatement(
|
||||
"SELECT * FROM player_stats WHERE player_uuid = ? AND stat_type = ?")) {
|
||||
|
||||
stmt.setString(1, TEST_PLAYER_UUID.toString());
|
||||
stmt.setString(2, TEST_STAT_TYPE);
|
||||
|
||||
ResultSet rs = stmt.executeQuery();
|
||||
|
||||
Assertions.assertTrue(rs.next(), "Stat record should exist");
|
||||
Assertions.assertEquals(TEST_PLAYER_UUID.toString(), rs.getString("player_uuid"));
|
||||
Assertions.assertEquals(TEST_STAT_TYPE, rs.getString("stat_type"));
|
||||
Assertions.assertEquals(TEST_VALUE, rs.getInt("stat_value"));
|
||||
Assertions.assertEquals(TEST_BLOCK_ID, rs.getString("item_id"));
|
||||
Assertions.assertNotNull(rs.getTimestamp("timestamp"));
|
||||
|
||||
Assertions.assertFalse(rs.next(), "Should only have one matching record");
|
||||
}
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void tearDownEach() throws SQLException {
|
||||
// Clean up test data after each test
|
||||
try (Connection conn = dbManager.getConnection();
|
||||
PreparedStatement stmt = conn.prepareStatement(
|
||||
"DELETE FROM player_stats WHERE stat_type = ?")) {
|
||||
stmt.setString(1, TEST_STAT_TYPE);
|
||||
stmt.executeUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
static void tearDown() throws SQLException {
|
||||
// Perform any final cleanup if needed
|
||||
try (Connection conn = dbManager.getConnection();
|
||||
PreparedStatement stmt = conn.prepareStatement(
|
||||
"DELETE FROM player_stats WHERE stat_type = ?")) {
|
||||
stmt.setString(1, TEST_STAT_TYPE);
|
||||
stmt.executeUpdate();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user