View Javadoc
1   package booking.model.bo;
2   
3   import java.util.Random;
4   
5   import junit.framework.TestCase;
6   
7   import org.hibernate.Session;
8   import org.junit.AfterClass;
9   import org.junit.BeforeClass;
10  import org.junit.Test;
11  
12  import booking.model.util.HibernateUtil;
13  
14  public class ServicesBOTest extends TestCase {
15  
16  	private ServicesBO servicesBO;
17  
18  	@BeforeClass
19  	public void setUp() {
20  		FactoryBO factory = new FactoryBO();
21  		servicesBO = factory.servicesBO();
22  
23  	}
24  
25  	@AfterClass
26  	public void tearDown() {
27  
28  	}
29  
30  	@Test
31  	public void testLogin() {
32  
33  		try {
34  			Session session = HibernateUtil.getSessionFactory().getCurrentSession();
35  			assertNotNull(servicesBO.login("uoctfm@gmail.com", "P2ssword", session));
36  		} catch (Exception e) {
37  			e.printStackTrace();
38  			fail();
39  		}
40  	}
41  
42  	@Test
43  	public void testCreateUserWithPreferences() {
44  		try {
45  
46  			Random randomGenerator = new Random();
47  			int randomInt = randomGenerator.nextInt(10000);
48  			boolean created = servicesBO.createUSer("H", "test" + randomInt, "TestName", "TestSurname", new Long(
49  			        "93888777666"), "test" + randomInt + "@uoc.edu", "P@ssword", "A", "E", "M,A,E");
50  			assertEquals(true, created);
51  		} catch (Exception e) {
52  			e.printStackTrace();
53  			fail();
54  		}
55  	}
56  
57  	@Test
58  	public void testCreateUserWithoutPreferences() {
59  		try {
60  
61  			Random randomGenerator = new Random();
62  			int randomInt = randomGenerator.nextInt(10000);
63  
64  			boolean created = servicesBO.createUSer("H", "test" + randomInt, "TestName", "TestSurname", new Long(
65  			        "93888777666"), "test" + randomInt + "@uoc.edu", "P@ssword", "A", "", "");
66  			assertEquals(true, created);
67  		
68  		} catch (Exception e) {
69  			e.printStackTrace();
70  			fail();
71  		}
72  	}
73  
74  	public void testUpdateUserWithoutPreferences() {
75  		try {
76  
77  			Random randomGenerator = new Random();
78  			int randomInt = randomGenerator.nextInt(10000);
79  
80  			boolean updated = servicesBO.updateUser("3", "H", "test" + randomInt, "TestName", "TestSurname", new Long("93888777666"),
81  			        "test" + randomInt + "@uoc.edu", "P@ssword", "A", "", "");
82  			
83  			assertEquals(true, updated);
84  			
85  		} catch (Exception e) {
86  			e.printStackTrace();
87  			fail();
88  		}
89  	}
90  
91  	@Test
92  	public void testUpdateUserWithPreferences() {
93  		try {
94  
95  			Random randomGenerator = new Random();
96  			int randomInt = randomGenerator.nextInt(10000);
97  
98  			boolean updated = servicesBO.updateUser("3", "H", "test" + randomInt, "TestName", "TestSurname", new Long("93888777666"),
99  			        "test" + randomInt + "@uoc.edu", "P@ssword", "A", "", "M,A");
100 			
101 			assertEquals(true, updated);
102 			
103 		} catch (Exception e) {
104 			e.printStackTrace();
105 			fail();
106 		}
107 	}
108 
109 	@Test
110 	public void testRecoveryPassword() {
111 
112 		try {
113 
114 			//boolean recoveredPassword = servicesBO.recoveryPassword("uoctfm@gmail.com");
115 			//assertEquals(true, recoveredPassword);
116 
117 		} catch (Exception e) {
118 			e.printStackTrace();
119 			fail();
120 		}
121 	}
122 
123 }