r1 - 23 Nov 2006 - 14:53:30 - GleidsonEcheliYou are here: TWiki >  Doo Web  > ExemploDeUsoDoPrevayler > CriandoUmExemplo > CriandoUmExemploParte2 > CriandoUmExemploParte3 > CriandoUmExemploParte4

4. Criando um sistema prevalente (parte 4)

Agora vamos criar um classe de testes que vai utilizar nosso sistema para vermos como ele se comporta. Essa classe serve apenas como ilustração.

package testes;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.junit.Before;
import org.junit.Test;
import org.prevayler.Prevayler;
import org.prevayler.PrevaylerFactory;

import exemplo.AdicaoDeProblema;
import exemplo.Problema;
import exemplo.RemocaoDeProblema;
import exemplo.RetornoDeProblema;



public class Testes {
   
   Prevayler nossoSistema;

   @Before
   public void criarPrevayler() {
      try {
         PrevaylerFactory fábrica = new PrevaylerFactory();
         
         fábrica.configurePrevalenceDirectory("problemas");
         fábrica.configurePrevalentSystem(new ArrayList<Problema>());
         
         nossoSistema = fábrica.create();
         
      } catch (IOException e) {
         fail();
         e.printStackTrace();
      } catch (ClassNotFoundException e) {
         fail();
         e.printStackTrace();
      }
   }
   
   @Test
   public void inserirProblema() {
      Problema problema = new Problema("sala 3", "máquina 1", "Trava quando roda proteção de tela"); 
      
      nossoSistema.execute(new AdicaoDeProblema(problema));
      
      List<Problema> lista = (List<Problema>) nossoSistema.prevalentSystem();
      
      assertEquals(1, lista.size());
      
   }
   
   @Test
   public void retornarProblema() {
      try {
         Problema p = (Problema) nossoSistema.execute(new RetornoDeProblema(1));
         
         assertEquals("sala 3", p.retornarSala());
         assertEquals("máquina 1", p.retornarMáquina());
         assertEquals("Trava quando roda proteção de tela", p.retornarDescrição());
         
      } catch (Exception e) {
         fail();
         e.printStackTrace();
      }
   }
      
   @Test
   public void removerProblema() {
      nossoSistema.execute(new RemocaoDeProblema(1));
      
      List<Problema> lista = (List<Problema>) nossoSistema.prevalentSystem();
      
      assertEquals(0, lista.size());
   }
   
}

anterior


-- GleidsonEcheli - 23 Nov 2006
Edit | WYSIWYG | Attach | Printable | Raw View | Backlinks: Web, All Webs | History: r1 | More topic actions
 
Powered by TWiki
This site is powered by the TWiki collaboration platformCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback