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