-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
AdrianBalunan
committed
Apr 12, 2026
1 parent
7d0960c
commit f6d44f7
Showing
2 changed files
with
65 additions
and
140 deletions.
There are no files selected for viewing
140 changes: 0 additions & 140 deletions
140
...elpapplication/src/test/java/ntnu/systemutvikling/team6/database/DatabaseManagerTest.java
This file was deleted.
Oops, something went wrong.
65 changes: 65 additions & 0 deletions
65
...ehelpapplication/src/test/java/ntnu/systemutvikling/team6/database/DatabaseSetupTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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(); | ||
| }); | ||
| } | ||
| } | ||
| } |