Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package devmedia.srs.factory;
- import devmedia.srs.GenericDAO;
- import devmedia.srs.entity.Supplier;
- import java.util.List;
- import java.util.Vector;
- import junit.framework.TestCase;
- import static org.junit.Assert.*;
- /**
- *
- * @author systemhair
- */
- public class FactorySupplierTest extends TestCase{
- public FactorySupplierTest() {
- }
- private List<Supplier> savedSuppliers;
- protected void setUp() throws Exception {
- savedSuppliers = new Vector<Supplier>();
- savedSuppliers.add(new Supplier("The first supplier","first@email.com"));
- savedSuppliers.add(new Supplier("Just another one","another@another.com"));
- savedSuppliers.add(new Supplier("Test","testing@test.com.br"));
- savedSuppliers.add(new Supplier("The greatest","greatest@great.com.cz"));
- GenericDAO dao = new GenericDAO();
- for (Supplier s : savedSuppliers)
- dao.save(s);
- }
- public void testGetSupplierById() throws Exception{
- System.out.println("GetSupplierById");
- Supplier theOne = savedSuppliers.get(2);
- String id = theOne.getId();
- Supplier loaded = new FactorySupplier().getSupplierById(id);
- assertEquals(theOne.getId(), loaded.getId());
- assertEquals(theOne.getName(), loaded.getName());
- assertEquals(theOne.getEmail(), loaded.getEmail());
- }
- public void testGetSupplier() throws Exception{
- System.out.println("GetSupplier");
- List<SearchCriteria> parameters = new Vector<SearchCriteria>();
- FactorySupplier factory = new FactorySupplier();
- //Search by name
- parameters.add(new SearchCriteria(FactorySupplier.SEARCH_BY_NAME, "one"));
- List<Supplier> result = factory.getSupplier(parameters);
- assertTrue(result.size() == 2);
- assertTrue(result.contains(savedSuppliers.get(1)));
- assertTrue(result.contains(savedSuppliers.get(3)));
- //Searching excluding a word from the name
- parameters.clear();
- parameters.add(new SearchCriteria(FactorySupplier.SEARCH_NOT_BY_THIS_NAME, "Just"));
- result = factory.getSupplier(parameters);
- assertTrue(result.size() == 2);
- assertTrue(result.contains(savedSuppliers.get(1)));
- assertTrue(result.contains(savedSuppliers.get(2)));
- assertTrue(result.contains(savedSuppliers.get(3)));
- //Searching by e-mail
- parameters.clear();
- parameters.add(new SearchCriteria(FactorySupplier.SEARCH_BY_EMAIL, "first@email.com"));
- result = factory.getSupplier(parameters);
- assertTrue(result.size() == 1);
- assertTrue(result.contains(savedSuppliers.get(0)));
- //Mixed Search
- parameters.clear();
- parameters.add(new SearchCriteria(FactorySupplier.SEARCH_BY_NAME, "one"));
- parameters.add(new SearchCriteria(FactorySupplier.SEARCH_NOT_BY_THIS_NAME, "another"));
- assertTrue(result.size() == 1);
- assertTrue(result.contains(savedSuppliers.get(0)));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement