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