Advertisement
Guest User

Untitled

a guest
May 31st, 2017
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.01 KB | None | 0 0
  1. package devmedia.srs.factory;
  2.  
  3. import devmedia.srs.GenericDAO;
  4. import devmedia.srs.entity.Supplier;
  5. import java.util.List;
  6. import java.util.Vector;
  7. import junit.framework.TestCase;
  8. import static org.junit.Assert.*;
  9.  
  10. /**
  11.  *
  12.  * @author systemhair
  13.  */
  14. public class FactorySupplierTest extends TestCase{
  15.  
  16.     public FactorySupplierTest() {
  17.     }
  18.  
  19.     private List<Supplier> savedSuppliers;
  20.  
  21.     protected void setUp() throws Exception {
  22.  
  23.         savedSuppliers = new Vector<Supplier>();
  24.         savedSuppliers.add(new Supplier("The first supplier","first@email.com"));
  25.         savedSuppliers.add(new Supplier("Just another one","another@another.com"));
  26.         savedSuppliers.add(new Supplier("Test","testing@test.com.br"));
  27.         savedSuppliers.add(new Supplier("The greatest","greatest@great.com.cz"));
  28.         GenericDAO dao = new GenericDAO();
  29.         for (Supplier s : savedSuppliers)
  30.             dao.save(s);
  31.     }
  32.  
  33.     public void testGetSupplierById() throws Exception{
  34.  
  35.         System.out.println("GetSupplierById");
  36.         Supplier theOne = savedSuppliers.get(2);
  37.         String id = theOne.getId();
  38.         Supplier loaded = new FactorySupplier().getSupplierById(id);
  39.         assertEquals(theOne.getId(), loaded.getId());
  40.         assertEquals(theOne.getName(), loaded.getName());
  41.         assertEquals(theOne.getEmail(), loaded.getEmail());
  42.     }
  43.  
  44.     public void testGetSupplier() throws Exception{
  45.  
  46.         System.out.println("GetSupplier");
  47.         List<SearchCriteria> parameters = new Vector<SearchCriteria>();
  48.         FactorySupplier factory = new FactorySupplier();
  49.  
  50.         //Search by name
  51.         parameters.add(new SearchCriteria(FactorySupplier.SEARCH_BY_NAME, "one"));
  52.         List<Supplier> result = factory.getSupplier(parameters);
  53.         assertTrue(result.size() == 2);
  54.         assertTrue(result.contains(savedSuppliers.get(1)));
  55.         assertTrue(result.contains(savedSuppliers.get(3)));
  56.  
  57.         //Searching excluding a word from the name
  58.         parameters.clear();
  59.         parameters.add(new SearchCriteria(FactorySupplier.SEARCH_NOT_BY_THIS_NAME, "Just"));
  60.         result = factory.getSupplier(parameters);
  61.         assertTrue(result.size() == 2);
  62.         assertTrue(result.contains(savedSuppliers.get(1)));
  63.         assertTrue(result.contains(savedSuppliers.get(2)));
  64.         assertTrue(result.contains(savedSuppliers.get(3)));
  65.  
  66.         //Searching by e-mail
  67.         parameters.clear();
  68.         parameters.add(new SearchCriteria(FactorySupplier.SEARCH_BY_EMAIL, "first@email.com"));
  69.         result = factory.getSupplier(parameters);
  70.         assertTrue(result.size() == 1);
  71.         assertTrue(result.contains(savedSuppliers.get(0)));
  72.  
  73.         //Mixed Search
  74.         parameters.clear();
  75.         parameters.add(new SearchCriteria(FactorySupplier.SEARCH_BY_NAME, "one"));
  76.         parameters.add(new SearchCriteria(FactorySupplier.SEARCH_NOT_BY_THIS_NAME, "another"));
  77.         assertTrue(result.size() == 1);
  78.         assertTrue(result.contains(savedSuppliers.get(0)));
  79.     }
  80.  
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement