Mass removal of all Tabs (Style Warnings)
[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 import static org.hamcrest.CoreMatchers.*;
26 import static org.mockito.Mockito.*;
27 import org.junit.*;
28 import org.mockito.*;
29 // import org.junit.runner.RunWith;
30 // import org.powermock.modules.junit4.PowerMockRunner;
31
32 import java.util.Date;
33 import java.util.List;
34 import java.util.ArrayList;
35 import java.util.Map;
36 import java.util.Timer;
37
38 import org.onap.aaf.auth.cache.Cache;
39 import org.onap.aaf.auth.cache.Cache.Dated;
40 import org.onap.aaf.auth.dao.CIDAO;
41 import org.onap.aaf.auth.dao.Cached;
42 import org.onap.aaf.auth.dao.Cached.Getter;
43 import org.onap.aaf.auth.dao.JU_Cached.DataStub;
44 import org.onap.aaf.auth.dao.cass.CacheableData;
45 import org.onap.aaf.auth.env.AuthzEnv;
46 import org.onap.aaf.auth.env.AuthzTrans;
47 import org.onap.aaf.auth.layer.Result;
48 import org.onap.aaf.misc.env.Trans;
49
50 // @RunWith(PowerMockRunner.class)
51 public class JU_Cached {
52
53     @Mock
54     CIDAO<Trans> ciDaoMock;
55
56     @Mock
57     AuthzEnv authzEnvMock;
58
59     @Mock
60     CIDAO<AuthzTrans> cidaoATMock;
61     
62     String name = "nameString";
63
64     @Before
65     public void setUp(){
66         MockitoAnnotations.initMocks(this);
67     }
68     
69     @Test
70     public void testCachedIdx(){
71         Cached<Trans, DataStub> cached = new Cached<Trans, DataStub>(ciDaoMock, name, 1, 30000L);
72         assertThat(cached.cacheIdx("1234567890"), is(0));
73     }
74     
75     @Test
76     public void testInvalidate(){
77         Cached<Trans, DataStub> cached = new Cached<Trans, DataStub>(ciDaoMock, name, 5, 30000L);
78         cached.add("test", new ArrayList<>());
79         cached.invalidate("test");
80         cached.invalidate("test1");
81     }
82     
83     @SuppressWarnings("static-access")
84     @Test
85     public void testStopTimer(){
86         Cached<Trans, DataStub> cached = new Cached<Trans, DataStub>(ciDaoMock, name, 1, 30000L);
87         cached.stopTimer();
88         assertTrue(true);
89     }
90
91     @SuppressWarnings("static-access")
92     @Test
93     public void testStartRefresh(){
94         Cached<Trans, DataStub> cached = new Cached<Trans, DataStub>(ciDaoMock, name, 1, 30000L);
95         cached.startRefresh(authzEnvMock, cidaoATMock);
96         assertTrue(true);
97     }
98 //    @Mock
99 //    Trans transMock;
100 //    @Mock
101 //    Getter<DAO> getterMock;
102 //    
103 //    @Test
104 //    public void testGet(){
105 //        cached.get(transMock, name, getterMock);
106 //        fail("not implemented");
107 //    }
108 //    
109 //    @SuppressWarnings("unchecked")
110 //    public Result<List<DATA>> get(TRANS trans, String key, Getter<DATA> getter) {
111 //        List<DATA> ld = null;
112 //        Result<List<DATA>> rld = null;
113 //        
114 //        int cacheIdx = cacheIdx(key);
115 //        Map<String, Dated> map = ((Map<String,Dated>)cache[cacheIdx]);
116 //        
117 //        // Check for saved element in cache
118 //        Dated cached = map.get(key);
119 //        // Note: These Segment Timestamps are kept up to date with DB
120 //        Date dbStamp = info.get(trans, name,cacheIdx);
121 //        
122 //        // Check for cache Entry and whether it is still good (a good Cache Entry is same or after DBEntry, so we use "before" syntax)
123 //        if(cached!=null && dbStamp.before(cached.timestamp)) {
124 //            ld = (List<DATA>)cached.data;
125 //            rld = Result.ok(ld);
126 //        } else {
127 //            rld = getter.get();
128 //            if(rld.isOK()) { // only store valid lists
129 //                map.put(key, new Dated(rld.value));  // successful item found gets put in cache
130 ////            } else if(rld.status == Result.ERR_Backend){
131 ////                map.remove(key);
132 //            }
133 //        }
134 //        return rld;
135 //    }
136
137     class DataStub extends CacheableData {
138         @Override public int[] invalidate(Cached<?, ?> cache) { return null; }
139     }
140 }