1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.jboss.as.quickstarts.tasksJsf;
18
19 import static org.junit.Assert.assertEquals;
20
21 import java.io.FileNotFoundException;
22
23 import javax.inject.Inject;
24
25 import org.jboss.arquillian.container.test.api.Deployment;
26 import org.jboss.arquillian.junit.Arquillian;
27 import org.jboss.as.quickstarts.tasksJsf.Task;
28 import org.jboss.as.quickstarts.tasksJsf.TaskDao;
29 import org.jboss.as.quickstarts.tasksJsf.TaskList;
30 import org.jboss.as.quickstarts.tasksJsf.TaskListBean;
31 import org.jboss.as.quickstarts.tasksJsf.User;
32 import org.jboss.shrinkwrap.api.spec.WebArchive;
33 import org.junit.Test;
34 import org.junit.runner.RunWith;
35
36
37
38
39 @RunWith(Arquillian.class)
40 public class TaskListBeanTest {
41
42 public static final String WEBAPP_SRC = "src/main/webapp";
43
44 @Deployment
45 public static WebArchive deployment() throws IllegalArgumentException, FileNotFoundException {
46 return new DefaultDeployment(true).withPersistence().withImportedData().getArchive()
47 .addClasses(User.class, Task.class, TaskList.class, TaskListBean.class, TaskDao.class, TaskDaoStub.class, Testing.class);
48 }
49
50 @Inject
51 private TaskDao taskDaoStub;
52
53 @Inject
54 private TaskList taskList;
55
56 @Test
57 public void dao_method_getAll_should_be_called_only_once_on() {
58 taskList.getAll();
59 taskList.getAll();
60 taskList.getAll();
61 assertEquals(1, ((TaskDaoStub) taskDaoStub).getGetAllCallsCount());
62 }
63
64 @Test
65 public void dao_method_getAll_should_be_called_after_invalidation() {
66 taskList.getAll();
67 taskList.getAll();
68 assertEquals(1, ((TaskDaoStub) taskDaoStub).getGetAllCallsCount());
69 taskList.invalidate();
70 assertEquals(1, ((TaskDaoStub) taskDaoStub).getGetAllCallsCount());
71 taskList.getAll();
72 taskList.getAll();
73 assertEquals(2, ((TaskDaoStub) taskDaoStub).getGetAllCallsCount());
74 }
75 }