Database script continue + tests Junit5 #4
This commit is contained in:
parent
feee1885bd
commit
641d298bd3
@ -18,4 +18,13 @@ public class QueryGenerator {
|
||||
return "public." + '"' + s + '"';
|
||||
}
|
||||
|
||||
public static String getIdWithNameFrom(String table, String name) {
|
||||
return "SELECT 'id' FROM " + getTable(table) + "WHERE nom ='" + name + "'";
|
||||
}
|
||||
|
||||
public static String getNameWithIdFrom(String table, int d) {
|
||||
return "SELECT name FROM " + getTable(table) + "WHERE id =" + d;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -40,5 +40,4 @@ public class Record {
|
||||
return String.format("%-20.30s %-30.30s %-20.30s%n", this.getId(), this.getNom(), this.getImg());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -84,6 +84,14 @@ public class Table {
|
||||
return " " + this.getList();
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
if(list.isEmpty()) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
43
tests/database/TestDatabse.java
Normal file
43
tests/database/TestDatabse.java
Normal file
@ -0,0 +1,43 @@
|
||||
package database;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class TestDatabse {
|
||||
|
||||
Table t;
|
||||
|
||||
@BeforeEach
|
||||
private void initialize() {
|
||||
System.out.println("=====Initialisation du test=====");
|
||||
t = new Table("Table de Test");
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
private void free() {
|
||||
System.out.println("=====Fin du test=====\n\n\n");
|
||||
}
|
||||
|
||||
@Test
|
||||
private void testDBConnexion() {
|
||||
try (Connection connection = DriverManager.getConnection("jdbc:postgresql://localhost:5432/ShadowHunterDatabase", "shManager", "shadowhunter1234")) { //notre utilisateur que l'on utilisera (:
|
||||
|
||||
System.out.println("Connected to PostgreSQL database!");
|
||||
} catch (SQLException e) {
|
||||
System.out.println("Connection failure.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
private void getEntireTableCartesLumiere() {
|
||||
t.remplirTableAllFrom("CartesLumiere");
|
||||
Assert.assertFalse(t.isEmpty());
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user