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 com.att.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.powermock.modules.junit4.PowerMockRunner;
\r
38 import com.att.authz.env.AuthzEnv;
\r
39 import com.att.authz.env.AuthzTrans;
\r
40 import com.att.authz.layer.Result;
\r
41 import com.att.cache.Cache;
\r
42 import com.att.cache.Cache.Dated;
\r
43 import com.att.dao.Cached.Getter;
\r
44 //import com.att.dao.Cached.Refresh;
\r
45 import com.att.inno.env.Trans;
\r
47 @RunWith(PowerMockRunner.class)
\r
48 public class JU_Cached {
\r
51 CIDAO<Trans> ciDaoMock;
\r
53 AuthzEnv authzEnvMock;
\r
55 CIDAO<AuthzTrans> cidaoATMock;
\r
57 String name = "nameString";
\r
60 public void setUp(){
\r
61 cached = new Cached(ciDaoMock, name, 0);
\r
64 @Test(expected=ArithmeticException.class)
\r
65 public void testCachedIdx(){
\r
66 int Result = cached.cacheIdx("1234567890");
\r
69 @Test(expected=ArithmeticException.class)
\r
70 public void testInvalidate(){
\r
71 int Res = cached.invalidate(name);
\r
74 @SuppressWarnings("static-access")
\r
76 public void testStopTimer(){
\r
81 @SuppressWarnings("static-access")
\r
83 public void testStartRefresh(){
\r
84 cached.startRefresh(authzEnvMock, cidaoATMock);
\r
90 // Getter<DAO> getterMock;
\r
93 // public void testGet(){
\r
94 // cached.get(transMock, name, getterMock);
\r
95 // fail("not implemented");
\r
98 // @SuppressWarnings("unchecked")
\r
99 // public Result<List<DATA>> get(TRANS trans, String key, Getter<DATA> getter) {
\r
100 // List<DATA> ld = null;
\r
101 // Result<List<DATA>> rld = null;
\r
103 // int cacheIdx = cacheIdx(key);
\r
104 // Map<String, Dated> map = ((Map<String,Dated>)cache[cacheIdx]);
\r
106 // // Check for saved element in cache
\r
107 // Dated cached = map.get(key);
\r
108 // // Note: These Segment Timestamps are kept up to date with DB
\r
109 // Date dbStamp = info.get(trans, name,cacheIdx);
\r
111 // // 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
112 // if(cached!=null && dbStamp.before(cached.timestamp)) {
\r
113 // ld = (List<DATA>)cached.data;
\r
114 // rld = Result.ok(ld);
\r
116 // rld = getter.get();
\r
117 // if(rld.isOK()) { // only store valid lists
\r
118 // map.put(key, new Dated(rld.value)); // successful item found gets put in cache
\r
119 //// } else if(rld.status == Result.ERR_Backend){
\r
120 //// map.remove(key);
\r