MatrixBerryCore
AConfRepoMgrTC.m
Go to the documentation of this file.
1 classdef AConfRepoMgrTC < matlab.unittest.TestCase
2  properties (Access=protected)
3  cm
4  SDefaultEthalon=struct('firstProp','alpha','secondProp','beta');
5  factory
6  end
7  methods (Access=protected)
8  function self=initData(self)
9  import mxberry.conf.test.*;
10  self.cm=self.factory.getInstance();
11  self.cm.removeAll();
12  SConfA=genteststruct(1);
13  SConfB=genteststruct(2);
14  metaA=struct('a','1','b','2');
15  metaB=struct('a','11','b','22');
16  %
17  self.cm.putConf('testConfA',SConfA,100,metaA);
18  self.cm.putConf('testConfB',SConfB,200,metaB);
19  end
20  end
21  methods
22  function self = AConfRepoMgrTC(varargin)
23  self = self@matlab.unittest.TestCase(varargin{:});
24  end
25  end
26  properties (MethodSetupParameter, Abstract)
27  factoryParam
28  end
29  methods (TestMethodSetup)
30  function self = setUp(self,factoryParam)
31  self.factory=factoryParam;
32  self=self.initData();
33  end
34  end
35  methods (Test)
36  function self = test_setGetConf(self)
37  import mxberry.conf.test.*;
38  SConf=genteststruct(3);
39  metaData=struct('a','111','b','222');
40  self.cm.putConf('testConfA',SConf,3,metaData);
41  [SRes,confVersion,metaDataRes]=self.cm.getConf('testConfA');
42  self.verifyEqual(isequaln(SConf,SRes),true);
43  metaData.version='3';
44  self.verifyEqual(isequaln(metaData,metaDataRes),true);
45  self.verifyEqual(isequaln(3,confVersion),true);
46  end
47  function self = test_copyConfAndgetConfList(self)
48  import mxberry.conf.test.*;
49  SConf=genteststruct(3);
50  self.cm.putConf('testConfA',SConf);
51  self.cm.copyConf('testConfA','testConfAA');
52  SRes=self.cm.getConf('testConfAA');
53  self.verifyEqual(isequaln(SConf,SRes),true);
54  self.cm.removeConf('testConfB');
55  confNameList=self.cm.getConfNameList();
56  isEqual=isequal(sort({'testConfA','testConfAA'}),...
57  sort(confNameList));
58  self.verifyEqual(isEqual,true);
59  end
60  function self = test_isParam(self)
61  import mxberry.conf.test.*;
62  SConf=genteststruct(3);
63  self.cm.putConf('testConfA',SConf);
64  self.cm.selectConf('testConfA');
65  isPos=self.cm.isParam('dConf.gen.cdefs.gen.instTypeCode');
66  self.verifyEqual(isPos,true);
67  isPos=self.cm.isParam('dConf.gen.cdefs.gen.instTypeCode__');
68  self.verifyEqual(isPos,false);
69  isPos=self.cm.isParam('.dConf.gen.cdefs.gen.instTypeCode');
70  self.verifyEqual(isPos,true);
71 
72  end
73  function self = test_setGetParamWithDot(self)
74  import mxberry.conf.test.*;
75  %
76  paramNameList={'.dConf.backtest.calc.pairForecast.meanDec.nLags',...
77  'dConf.backtest.calc.pairForecast.meanDec.nLags'};
78  for iParam=1:length(paramNameList)
79  self=self.initData();
80  paramName=paramNameList{iParam};
81  self.cm.selectConf('testConfA');
82  paramVal=self.cm.getParam(paramName);
83  paramVal=paramVal+3;
84  self.cm.setParam(paramName,paramVal);
85  paramVal2=self.cm.getParam(paramName);
86  self.verifyEqual(isequaln(paramVal,paramVal2),true);
87  self.cm.selectConf('testConfB');
88  self.cm.setParam(paramName,Inf);
89  paramVal3=self.cm.getParam(paramName);
90  self.verifyEqual(isequaln(Inf,paramVal3),true);
91  self.cm.selectConf('testConfA');
92  paramVal5=self.cm.getParam(paramName);
93  self.verifyEqual(isequaln(paramVal,paramVal5),true);
94  end
95  end
96  function self = test_setGetParamNegative(self) import mxberry.conf.test.*;
97  %
98  self=self.initData();
99  paramName='.dConf.backtest.calc.pairForecast.meanDec.nLags123';
100  self.cm.selectConf('testConfA');
101  try
102  self.cm.getParam(paramName);
103  self.verifyEqual(true,false);
104  catch meObj
105  isOk=~isempty(strfind(meObj.identifier,...
106  'CONFREPOMANAGERANYSTORAGE:GETPARAM:invalidParam'));
107  self.verifyEqual(isOk,true);
108  end
109  end
110  function self = test_setParamInCache(self)
111  import mxberry.conf.test.*;
112  %
113  paramNameList={'.dConf.backtest.calc.pairForecast.meanDec.nLags',...
114  'dConf.backtest.calc.pairForecast.meanDec.nLags'};
115  for iParam=1:length(paramNameList)
116  self=self.initData();
117  paramName=paramNameList{iParam};
118  self.cm.selectConf('testConfA');
119  origParamValue=self.cm.getParam(paramName);
120  paramValue=rand(1);
121  self.cm.setParam(paramName,paramValue,'writeDepth','cache');
122  self.verifyEqual(true,self.cm.isParam(paramName));
123  self.verifyEqual(paramValue,self.cm.getParam(paramName));
124  self.cm.flushCache();
125  self.cm.selectConf('testConfA');
126  self.verifyEqual(true,self.cm.isParam(paramName));
127  self.verifyEqual(origParamValue,self.cm.getParam(paramName));
128  paramName=[paramName,'_2']; %#ok<AGROW>
129  paramValue=rand(1);
130  self.cm.setParam(paramName,paramValue,'writeDepth','cache');
131  self.verifyEqual(true,self.cm.isParam(paramName));
132  self.verifyEqual(paramValue,self.cm.getParam(paramName));
133  self.cm.flushCache();
134  self.cm.selectConf('testConfA');
135  self.verifyEqual(false,self.cm.isParam(paramName));
136  end
137  end
138  end
139 end
function genteststruct(in inpNum)