Skip to content

Commit

Permalink
Fix: Fixed DatabaseSetupTest
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrianBalunan committed Apr 12, 2026
1 parent 7d0960c commit f6d44f7
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 140 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package ntnu.systemutvikling.team6.database;

import static org.junit.jupiter.api.Assertions.*;

import java.sql.*;
import java.util.ArrayList;
import java.util.List;
import ntnu.systemutvikling.team6.database.Readers.CharitySelect;
import ntnu.systemutvikling.team6.database.Readers.DonationSelect;
import ntnu.systemutvikling.team6.models.Charity;
import ntnu.systemutvikling.team6.models.CharityRegistry;
import ntnu.systemutvikling.team6.service.APIToDatabaseService;
import org.junit.jupiter.api.*;

class DatabaseSetupTest {

private DatabaseSetup dbManager;
private APIToDatabaseService service;
private CharitySelect charitySelect;
private DonationSelect donationSelect;

@BeforeEach
public void setUp() throws SQLException {
DatabaseConnection conn = new DatabaseConnection();
this.dbManager = new DatabaseSetup(conn);
this.service = new APIToDatabaseService(conn);
this.charitySelect = new CharitySelect(conn);
this.donationSelect = new DonationSelect(conn);
}

// Make sure you're connected to the NTNU network for this to work
@Test
public void testConnectionShouldReturnTrue() {
assertTrue(dbManager.testConnection());
}

@Test
void createCharitiesTableShouldCreateTableSuccessfully() throws SQLException {
dbManager.createTables();

try (Connection conn = new DatabaseConnection().getMySqlConnection()) {
ResultSet rs = conn.getMetaData().getTables(null, null, "Charities", null);

assertTrue(rs.next());
}
}


@Test
void tempTableShouldNotExistAfterUpdating() throws SQLException {
Charity charity = new Charity("99999", "https://temp.no", "Temp Charity", false, "approved");

service.addAPIDataToTable(List.of(charity));

try (Connection conn = new DatabaseConnection().getMySqlConnection()) {
PreparedStatement stmt = conn.prepareStatement("SELECT * FROM temp_api_charities");

assertThrows(
java.sql.SQLSyntaxErrorException.class,
() -> {
ResultSet rs = stmt.executeQuery();
});
}
}
}

0 comments on commit f6d44f7

Please sign in to comment.