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