1 /*******************************************************************************
2 * ============LICENSE_START====================================================
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
11 * * http://www.apache.org/licenses/LICENSE-2.0
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====================================================
21 ******************************************************************************/
22 package org.onap.aaf.auth.dao;
24 import static org.junit.Assert.*;
26 import java.util.Date;
27 import java.util.List;
29 import java.util.Timer;
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;
46 @RunWith(PowerMockRunner.class)
47 public class JU_Cached {
50 CIDAO<Trans> ciDaoMock;
52 AuthzEnv authzEnvMock;
54 CIDAO<AuthzTrans> cidaoATMock;
56 String name = "nameString";
60 cached = new Cached(ciDaoMock, name, (int)0, 30000L);
63 @Test(expected=ArithmeticException.class)
64 public void testCachedIdx(){
65 int Result = cached.cacheIdx("1234567890");
68 @Test(expected=ArithmeticException.class)
69 public void testInvalidate(){
70 int Res = cached.invalidate(name);
73 @SuppressWarnings("static-access")
75 public void testStopTimer(){
80 @SuppressWarnings("static-access")
82 public void testStartRefresh(){
83 cached.startRefresh(authzEnvMock, cidaoATMock);
89 // Getter<DAO> getterMock;
92 // public void testGet(){
93 // cached.get(transMock, name, getterMock);
94 // fail("not implemented");
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;
102 // int cacheIdx = cacheIdx(key);
103 // Map<String, Dated> map = ((Map<String,Dated>)cache[cacheIdx]);
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);
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);
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);