View Javadoc
1   /*
2    * JBoss, Home of Professional Open Source
3    * Copyright 2014, Red Hat, Inc. and/or its affiliates, and individual
4    * contributors by the @authors tag. See the copyright.txt in the
5    * distribution for a full listing of individual contributors.
6    *
7    * Licensed under the Apache License, Version 2.0 (the "License");
8    * you may not use this file except in compliance with the License.
9    * You may obtain a copy of the License at
10   * http://www.apache.org/licenses/LICENSE-2.0
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
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   * @author Lukas Fryc
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  }