package de.ticketsystem.database; import de.ticketsystem.TicketPlugin; import de.ticketsystem.model.Ticket; import de.ticketsystem.model.TicketStatus; import org.bukkit.plugin.Plugin; import org.junit.jupiter.api.*; import java.io.File; import java.util.UUID; import static org.junit.jupiter.api.Assertions.*; class DatabaseManagerFileTest { // Dummy-Plugin-Implementierung für Tests (vermeidet Mockito) private DatabaseManager db; private File testFile; private org.bukkit.configuration.file.YamlConfiguration config; @BeforeEach void setUp() { testFile = new File("build/testdata/testdata.yml"); if (testFile.exists()) testFile.delete(); config = new org.bukkit.configuration.file.YamlConfiguration(); db = new DatabaseManager(testFile, config); } @Test void testCreateAndGetTicket() { Ticket t = new Ticket(); t.setCreatorUUID(UUID.randomUUID()); t.setCreatorName("Tester"); t.setMessage("Testnachricht"); t.setWorldName("world"); t.setX(1.0); t.setY(2.0); t.setZ(3.0); t.setYaw(0); t.setPitch(0); t.setStatus(TicketStatus.OPEN); t.setCreatedAt(new java.sql.Timestamp(System.currentTimeMillis())); int id = db.createTicket(t); assertTrue(id > 0); Ticket loaded = db.getTicketById(id); assertNotNull(loaded); assertEquals("Tester", loaded.getCreatorName()); } @Test void testExportImportTickets() { Ticket t = new Ticket(); t.setCreatorUUID(UUID.randomUUID()); t.setCreatorName("ExportUser"); t.setMessage("ExportTest"); t.setWorldName("world"); t.setX(1.0); t.setY(2.0); t.setZ(3.0); t.setYaw(0); t.setPitch(0); t.setStatus(TicketStatus.OPEN); t.setCreatedAt(new java.sql.Timestamp(System.currentTimeMillis())); db.createTicket(t); File exportFile = new File("build/testdata/export.json"); int exported = db.exportTickets(exportFile); assertTrue(exported > 0); db.importTickets(exportFile); // sollte keine Exception werfen } @AfterEach void tearDown() { if (testFile.exists()) testFile.delete(); new File("build/testdata/export.json").delete(); } }