1 /*******************************************************************************
\r
2 * ============LICENSE_START====================================================
\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
11 * * http://www.apache.org/licenses/LICENSE-2.0
\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
20 * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
\r
22 ******************************************************************************/
\r
23 package org.onap.aaf.dao;
\r
25 import static org.junit.Assert.*;
\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
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.onap.aaf.authz.env.AuthzEnv;
\r
37 import org.onap.aaf.authz.env.AuthzTrans;
\r
38 import org.onap.aaf.authz.layer.Result;
\r
39 import org.onap.aaf.cache.Cache;
\r
40 import org.onap.aaf.cache.Cache.Dated;
\r
41 import org.onap.aaf.dao.CIDAO;
\r
42 import org.onap.aaf.dao.Cached;
\r
43 import org.onap.aaf.dao.Cached.Getter;
\r
44 import org.powermock.modules.junit4.PowerMockRunner;
\r
46 //import org.onap.aaf.dao.Cached.Refresh;
\r
47 import org.onap.aaf.inno.env.Trans;
\r
49 @RunWith(PowerMockRunner.class)
\r
50 public class JU_Cached {
\r
53 CIDAO<Trans> ciDaoMock;
\r
55 AuthzEnv authzEnvMock;
\r
57 CIDAO<AuthzTrans> cidaoATMock;
\r
59 String name = "nameString";
\r
62 public void setUp(){
\r
63 cached = new Cached(ciDaoMock, name, 0);
\r
66 @Test(expected=ArithmeticException.class)
\r
67 public void testCachedIdx(){
\r
68 int Result = cached.cacheIdx("1234567890");
\r
71 @Test(expected=ArithmeticException.class)
\r
72 public void testInvalidate(){
\r
73 int Res = cached.invalidate(name);
\r
76 @SuppressWarnings("static-access")
\r
78 public void testStopTimer(){
\r
83 @SuppressWarnings("static-access")
\r
85 public void testStartRefresh(){
\r
86 cached.startRefresh(authzEnvMock, cidaoATMock);
\r
92 // Getter<DAO> getterMock;
\r
95 // public void testGet(){
\r
96 // cached.get(transMock, name, getterMock);
\r
97 // fail("not implemented");
\r
100 // @SuppressWarnings("unchecked")
\r
101 // public Result<List<DATA>> get(TRANS trans, String key, Getter<DATA> getter) {
\r
102 // List<DATA> ld = null;
\r
103 // Result<List<DATA>> rld = null;
\r
105 // int cacheIdx = cacheIdx(key);
\r
106 // Map<String, Dated> map = ((Map<String,Dated>)cache[cacheIdx]);
\r
108 // // Check for saved element in cache
\r
109 // Dated cached = map.get(key);
\r
110 // // Note: These Segment Timestamps are kept up to date with DB
\r
111 // Date dbStamp = info.get(trans, name,cacheIdx);
\r
113 // // 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
114 // if(cached!=null && dbStamp.before(cached.timestamp)) {
\r
115 // ld = (List<DATA>)cached.data;
\r
116 // rld = Result.ok(ld);
\r
118 // rld = getter.get();
\r
119 // if(rld.isOK()) { // only store valid lists
\r
120 // map.put(key, new Dated(rld.value)); // successful item found gets put in cache
\r
121 //// } else if(rld.status == Result.ERR_Backend){
\r
122 //// map.remove(key);
\r