Database script continue + tests Junit5 #4

This commit is contained in:
JunkJumper 2020-04-29 19:14:18 +02:00
parent feee1885bd
commit 641d298bd3
4 changed files with 60 additions and 1 deletions

View File

@ -18,4 +18,13 @@ public class QueryGenerator {
return "public." + '"' + s + '"'; 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;
}
} }

View File

@ -40,5 +40,4 @@ public class Record {
return String.format("%-20.30s %-30.30s %-20.30s%n", this.getId(), this.getNom(), this.getImg()); return String.format("%-20.30s %-30.30s %-20.30s%n", this.getId(), this.getNom(), this.getImg());
} }
} }

View File

@ -84,6 +84,14 @@ public class Table {
return " " + this.getList(); return " " + this.getList();
} }
public boolean isEmpty() {
if(list.isEmpty()) {
return true;
} else {
return false;
}
}

View 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());
}
}