Package test.serialisation

Source Code of test.serialisation.Test

package test.serialisation;

import java.io.File;
import java.io.IOException;
import java.rmi.RemoteException;
import java.util.HashMap;

import client.Client;

import profil.Profil;
import profil.Profil.Sexe;
import util.Constantes;
import util.ProfilException;
import util.Serialiser;

public class Test {

  public static void main(String[] args) {
    File f = new File(Constantes.PROFIL);
    f.delete();
   
    try {
      Client.newProfil(new Profil("tarek.tarek13", "azerty", "JAOUANI", "Tarek", Sexe.H));
      Client.newProfil(new Profil("kevkev69", "azerty", "FRANCES", "Kévin", Sexe.H));
      Client.newProfil(new Profil("dalleria", "azerty", "DALLE-RIVE", "Antoine", Sexe.H));
      Client.newProfil(new Profil("calleay", "azerty", "CALLEA", "Yohann", Sexe.H));
      Client.newProfil(new Profil("bab", "azerty", "CISSE", "Babacar", Sexe.H));
      Client.newProfil(new Profil("aitmachin", "azerty", "AIT-MAMA", "Meryeme", Sexe.F));
    } catch (IOException e) {
      System.err.println("Une erreur est survenue durant la création d'un profil.");
      System.exit(1);
    } catch (ProfilException e) {
      System.err.println("ProfilException : " + e.getMessage());
      System.exit(1);
    }
   
    try {
      HashMap<String,Profil> profils = Serialiser.deserialiser(Constantes.PROFIL);
     
      for (Profil p : profils.values())
        System.out.println(p.getPseudo());
    } catch (IOException e) {
      System.err.println("Lecture impossible du fichier sérialisé");
      e.printStackTrace();
      System.exit(1);
    }
   
    Profil p = null;
    try {
      p = Client.getProfil("tarek.tarek13");
    } catch (RemoteException e) {
      System.err.println("Remote Exception");
      System.exit(1);
    }
   
    try {
      p.setNom("JAOUAOUAOUANI");
    } catch (NullPointerException e) {
      System.err.println("Profil inexistant");
      System.exit(1);
    }
   
    try {
      Client.modifyProfil("tarek.tarek13", p);
    } catch (RemoteException e) {
      System.err.println("Remote Exception");
      System.exit(1);
    } catch (ProfilException e) {
      System.err.println("ProfilException : " + e.getMessage());
      System.exit(1);
    }
   
    try {
      System.out.println("\n------------------------\n");

      HashMap<String,Profil> profils = Serialiser.deserialiser(Constantes.PROFIL);
     
      for (Profil p2 : profils.values())
        System.out.println(p2.getNom());
    } catch (IOException e) {
      System.err.println("Lecture impossible du fichier sérialisé");
      System.exit(1);
    }
   
    try {
      System.out.println("\n------------------------\n");

      Client.deleteProfil("tarek.tarek13");
      HashMap<String,Profil> profils = Serialiser.deserialiser(Constantes.PROFIL);
     
      for (Profil p2 : profils.values())
        System.out.println(p2.getNom());
    } catch (RemoteException e) {
      System.err.println("Remote Exception");
      System.exit(1);
    } catch (IOException e) {
      System.err.println("Lecture impossible du fichier sérialisé");
      System.exit(1);
    }
  }

}
TOP

Related Classes of test.serialisation.Test

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.