ajoute de test maven
Esse commit está contido em:
pai
0245b5bbc0
commit
8367db646d
4 arquivos alterados com 111 adições e 47 exclusões
15
pom.xml
15
pom.xml
|
@ -9,6 +9,21 @@
|
||||||
<version>1.0-SNAPSHOT</version>
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
<!-- Dépendance pour JUnit 5 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.junit.jupiter</groupId>
|
||||||
|
<artifactId>junit-jupiter-api</artifactId>
|
||||||
|
<version>5.7.0</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.junit.jupiter</groupId>
|
||||||
|
<artifactId>junit-jupiter-engine</artifactId>
|
||||||
|
<version>5.7.0</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- Dépendance pour MySQL Connector -->
|
<!-- Dépendance pour MySQL Connector -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>mysql</groupId>
|
<groupId>mysql</groupId>
|
||||||
|
|
|
@ -3,7 +3,6 @@ package controller;
|
||||||
import database.DatabaseConnection;
|
import database.DatabaseConnection;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.*;
|
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
|
@ -15,61 +14,26 @@ public class AjoutUtilisateur extends JFrame {
|
||||||
private JTextField emailField;
|
private JTextField emailField;
|
||||||
private JComboBox<String> typeComboBox;
|
private JComboBox<String> typeComboBox;
|
||||||
private JButton ajouterButton;
|
private JButton ajouterButton;
|
||||||
private JButton retourAccueilButton;
|
private JButton retourButton;
|
||||||
|
|
||||||
public AjoutUtilisateur() {
|
public AjoutUtilisateur() {
|
||||||
setTitle("Ajouter un utilisateur");
|
setTitle("Ajouter un utilisateur");
|
||||||
setSize(400, 300);
|
setSize(400, 250);
|
||||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
setLocationRelativeTo(null);
|
setLocationRelativeTo(null);
|
||||||
setLayout(new GridBagLayout());
|
|
||||||
|
|
||||||
GridBagConstraints gbc = new GridBagConstraints();
|
|
||||||
gbc.insets = new Insets(10, 10, 10, 10);
|
|
||||||
gbc.fill = GridBagConstraints.HORIZONTAL;
|
|
||||||
|
|
||||||
|
|
||||||
JLabel nomLabel = new JLabel("Nom :");
|
JLabel nomLabel = new JLabel("Nom :");
|
||||||
gbc.gridx = 0;
|
|
||||||
gbc.gridy = 0;
|
|
||||||
add(nomLabel, gbc);
|
|
||||||
|
|
||||||
nomField = new JTextField();
|
nomField = new JTextField();
|
||||||
gbc.gridx = 1;
|
|
||||||
gbc.gridy = 0;
|
|
||||||
gbc.gridwidth = 2;
|
|
||||||
add(nomField, gbc);
|
|
||||||
|
|
||||||
JLabel emailLabel = new JLabel("Email :");
|
JLabel emailLabel = new JLabel("Email :");
|
||||||
gbc.gridx = 0;
|
|
||||||
gbc.gridy = 1;
|
|
||||||
add(emailLabel, gbc);
|
|
||||||
|
|
||||||
emailField = new JTextField();
|
emailField = new JTextField();
|
||||||
gbc.gridx = 1;
|
|
||||||
gbc.gridy = 1;
|
|
||||||
gbc.gridwidth = 2;
|
|
||||||
add(emailField, gbc);
|
|
||||||
|
|
||||||
JLabel typeLabel = new JLabel("Type d'utilisateur :");
|
JLabel typeLabel = new JLabel("Type d'utilisateur :");
|
||||||
gbc.gridx = 0;
|
|
||||||
gbc.gridy = 2;
|
|
||||||
add(typeLabel, gbc);
|
|
||||||
|
|
||||||
typeComboBox = new JComboBox<>(new String[]{"benevole", "personne_besoin", "validateur"});
|
typeComboBox = new JComboBox<>(new String[]{"benevole", "personne_besoin", "validateur"});
|
||||||
gbc.gridx = 1;
|
|
||||||
gbc.gridy = 2;
|
|
||||||
gbc.gridwidth = 2;
|
|
||||||
add(typeComboBox, gbc);
|
|
||||||
|
|
||||||
ajouterButton = new JButton("Ajouter");
|
ajouterButton = new JButton("Ajouter");
|
||||||
gbc.gridx = 1;
|
retourButton = new JButton("Retour à l'accueil");
|
||||||
gbc.gridy = 3;
|
|
||||||
add(ajouterButton, gbc);
|
|
||||||
|
|
||||||
retourAccueilButton = new JButton("Retour à l'accueil");
|
|
||||||
gbc.gridx = 1;
|
|
||||||
gbc.gridy = 4;
|
|
||||||
add(retourAccueilButton, gbc);
|
|
||||||
|
|
||||||
ajouterButton.addActionListener(new ActionListener() {
|
ajouterButton.addActionListener(new ActionListener() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -78,14 +42,51 @@ public class AjoutUtilisateur extends JFrame {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
retourAccueilButton.addActionListener(new ActionListener() {
|
retourButton.addActionListener(new ActionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
MainMenu menu = new MainMenu();
|
MainMenu mainMenu = new MainMenu();
|
||||||
menu.setVisible(true);
|
mainMenu.setVisible(true);
|
||||||
dispose();
|
dispose();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
GroupLayout layout = new GroupLayout(getContentPane());
|
||||||
|
getContentPane().setLayout(layout);
|
||||||
|
layout.setAutoCreateGaps(true);
|
||||||
|
layout.setAutoCreateContainerGaps(true);
|
||||||
|
|
||||||
|
layout.setHorizontalGroup(
|
||||||
|
layout.createSequentialGroup()
|
||||||
|
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.TRAILING)
|
||||||
|
.addComponent(nomLabel)
|
||||||
|
.addComponent(emailLabel)
|
||||||
|
.addComponent(typeLabel))
|
||||||
|
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
|
||||||
|
.addComponent(nomField)
|
||||||
|
.addComponent(emailField)
|
||||||
|
.addComponent(typeComboBox)
|
||||||
|
.addGroup(layout.createSequentialGroup()
|
||||||
|
.addComponent(ajouterButton)
|
||||||
|
.addGap(10, 10, 10)
|
||||||
|
.addComponent(retourButton)))
|
||||||
|
);
|
||||||
|
|
||||||
|
layout.setVerticalGroup(
|
||||||
|
layout.createSequentialGroup()
|
||||||
|
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
|
||||||
|
.addComponent(nomLabel)
|
||||||
|
.addComponent(nomField))
|
||||||
|
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
|
||||||
|
.addComponent(emailLabel)
|
||||||
|
.addComponent(emailField))
|
||||||
|
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
|
||||||
|
.addComponent(typeLabel)
|
||||||
|
.addComponent(typeComboBox))
|
||||||
|
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
|
||||||
|
.addComponent(ajouterButton)
|
||||||
|
.addComponent(retourButton))
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ajouterUtilisateur() {
|
private void ajouterUtilisateur() {
|
||||||
|
@ -93,6 +94,11 @@ public class AjoutUtilisateur extends JFrame {
|
||||||
String email = emailField.getText();
|
String email = emailField.getText();
|
||||||
String typeUtilisateur = (String) typeComboBox.getSelectedItem();
|
String typeUtilisateur = (String) typeComboBox.getSelectedItem();
|
||||||
|
|
||||||
|
if (nom.isEmpty() || email.isEmpty()) {
|
||||||
|
JOptionPane.showMessageDialog(this, "Veuillez remplir tous les champs.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
try (Connection connection = DatabaseConnection.getConnection()) {
|
try (Connection connection = DatabaseConnection.getConnection()) {
|
||||||
String sql = "INSERT INTO utilisateurs (nom, email, type_utilisateur) VALUES (?, ?, ?)";
|
String sql = "INSERT INTO utilisateurs (nom, email, type_utilisateur) VALUES (?, ?, ?)";
|
||||||
PreparedStatement statement = connection.prepareStatement(sql);
|
PreparedStatement statement = connection.prepareStatement(sql);
|
||||||
|
@ -103,6 +109,18 @@ public class AjoutUtilisateur extends JFrame {
|
||||||
JOptionPane.showMessageDialog(this, "Utilisateur ajouté avec succès !");
|
JOptionPane.showMessageDialog(this, "Utilisateur ajouté avec succès !");
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
JOptionPane.showMessageDialog(this, "Erreur lors de l'ajout de l'utilisateur.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
AjoutUtilisateur ajoutUtilisateur = new AjoutUtilisateur();
|
||||||
|
ajoutUtilisateur.setVisible(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,9 +5,9 @@ import java.sql.DriverManager;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
|
||||||
public class DatabaseConnection {
|
public class DatabaseConnection {
|
||||||
private static final String URL = "jdbc:mysql://localhost:3306/aide_personnes_db";
|
private static final String URL = "jdbc:mysql://srv-bdens.insa-toulouse.fr:3306/projet_gei_023";
|
||||||
private static final String USER = "root";
|
private static final String USER = "projet_gei_023";
|
||||||
private static final String PASSWORD = "@Abdo2001elouali";
|
private static final String PASSWORD = "ohQu4ood";
|
||||||
|
|
||||||
public static Connection getConnection() throws SQLException {
|
public static Connection getConnection() throws SQLException {
|
||||||
return DriverManager.getConnection(URL, USER, PASSWORD);
|
return DriverManager.getConnection(URL, USER, PASSWORD);
|
||||||
|
|
31
src/test/java/controller/AjoutUtilisateurTest.java
Arquivo normal
31
src/test/java/controller/AjoutUtilisateurTest.java
Arquivo normal
|
@ -0,0 +1,31 @@
|
||||||
|
package controller;
|
||||||
|
|
||||||
|
import controller.AjoutUtilisateur;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
class AjoutUtilisateurTest {
|
||||||
|
|
||||||
|
private AjoutUtilisateur ajoutUtilisateur;
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
void setUp() {
|
||||||
|
ajoutUtilisateur = new AjoutUtilisateur();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testAjoutUtilisateur() {
|
||||||
|
// Tester si l'interface est bien créée
|
||||||
|
assertNotNull(ajoutUtilisateur);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//beaucoup de test a ajouter aprés
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
Carregando…
Referência em uma nova issue