4e6bf7d7992116a4c1701a74e64abee0ce95d619
[aaf/authz.git] / authz-cass / src / test / java / com / att / dao / JU_Cached.java
1 /*******************************************************************************\r
2  * ============LICENSE_START====================================================\r
3  * * org.onap.aai\r
4  * * ===========================================================================\r
5  * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
6  * * Copyright © 2017 Amdocs\r
7  * * ===========================================================================\r
8  * * Licensed under the Apache License, Version 2.0 (the "License");\r
9  * * you may not use this file except in compliance with the License.\r
10  * * You may obtain a copy of the License at\r
11  * * \r
12  *  *      http://www.apache.org/licenses/LICENSE-2.0\r
13  * * \r
14  *  * Unless required by applicable law or agreed to in writing, software\r
15  * * distributed under the License is distributed on an "AS IS" BASIS,\r
16  * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
17  * * See the License for the specific language governing permissions and\r
18  * * limitations under the License.\r
19  * * ============LICENSE_END====================================================\r
20  * *\r
21  * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
22  * *\r
23  ******************************************************************************/\r
24 package com.att.dao;\r
25 \r
26 import static org.junit.Assert.*;\r
27 \r
28 import java.util.Date;\r
29 import java.util.List;\r
30 import java.util.Map;\r
31 import java.util.Timer;\r
32 \r
33 import org.junit.Before;\r
34 import org.junit.Test;\r
35 import org.junit.runner.RunWith;\r
36 import org.mockito.Mock;\r
37 import org.powermock.modules.junit4.PowerMockRunner;\r
38 \r
39 import com.att.authz.env.AuthzEnv;\r
40 import com.att.authz.env.AuthzTrans;\r
41 import com.att.authz.layer.Result;\r
42 import com.att.cache.Cache;\r
43 import com.att.cache.Cache.Dated;\r
44 import com.att.dao.Cached.Getter;\r
45 //import com.att.dao.Cached.Refresh;\r
46 import com.att.inno.env.Trans;\r
47 \r
48 @RunWith(PowerMockRunner.class)\r
49 public class JU_Cached {\r
50         Cached cached;\r
51         @Mock\r
52         CIDAO<Trans> ciDaoMock;\r
53         @Mock\r
54         AuthzEnv authzEnvMock;\r
55         @Mock\r
56         CIDAO<AuthzTrans> cidaoATMock;\r
57         \r
58         String name = "nameString";\r
59         \r
60         @Before\r
61         public void setUp(){\r
62                 cached = new Cached(ciDaoMock, name, 0);\r
63         }\r
64         \r
65         @Test(expected=ArithmeticException.class)\r
66         public void testCachedIdx(){\r
67                 int Result = cached.cacheIdx("1234567890");             \r
68         }\r
69         \r
70         @Test(expected=ArithmeticException.class)\r
71         public void testInvalidate(){\r
72                 int Res = cached.invalidate(name);\r
73         }\r
74         \r
75         @SuppressWarnings("static-access")\r
76         @Test\r
77         public void testStopTimer(){\r
78                 cached.stopTimer();\r
79                 assertTrue(true);\r
80         }\r
81 \r
82         @SuppressWarnings("static-access")\r
83         @Test\r
84         public void testStartRefresh(){\r
85                 cached.startRefresh(authzEnvMock, cidaoATMock);\r
86                 assertTrue(true);\r
87         }\r
88 //      @Mock\r
89 //      Trans transMock;\r
90 //      @Mock\r
91 //      Getter<DAO> getterMock;\r
92 //      \r
93 //      @Test\r
94 //      public void testGet(){\r
95 //              cached.get(transMock, name, getterMock);\r
96 //              fail("not implemented");\r
97 //      }\r
98 //      \r
99 //      @SuppressWarnings("unchecked")\r
100 //      public Result<List<DATA>> get(TRANS trans, String key, Getter<DATA> getter) {\r
101 //              List<DATA> ld = null;\r
102 //              Result<List<DATA>> rld = null;\r
103 //              \r
104 //              int cacheIdx = cacheIdx(key);\r
105 //              Map<String, Dated> map = ((Map<String,Dated>)cache[cacheIdx]);\r
106 //              \r
107 //              // Check for saved element in cache\r
108 //              Dated cached = map.get(key);\r
109 //              // Note: These Segment Timestamps are kept up to date with DB\r
110 //              Date dbStamp = info.get(trans, name,cacheIdx);\r
111 //              \r
112 //              // Check for cache Entry and whether it is still good (a good Cache Entry is same or after DBEntry, so we use "before" syntax)\r
113 //              if(cached!=null && dbStamp.before(cached.timestamp)) {\r
114 //                      ld = (List<DATA>)cached.data;\r
115 //                      rld = Result.ok(ld);\r
116 //              } else {\r
117 //                      rld = getter.get();\r
118 //                      if(rld.isOK()) { // only store valid lists\r
119 //                              map.put(key, new Dated(rld.value));  // successful item found gets put in cache\r
120 ////                    } else if(rld.status == Result.ERR_Backend){\r
121 ////                            map.remove(key);\r
122 //                      }\r
123 //              }\r
124 //              return rld;\r
125 //      }\r
126 }\r