MatrixBerryCore
ConfRepoMgrCommonTC.m
Go to the documentation of this file.
1 classdef ConfRepoMgrCommonTC < matlab.unittest.TestCase
2  properties (Access=protected)
3  cm
4  SDefaultEthalon=struct('firstProp','alpha','secondProp','beta');
5  factory
6  end
7  %
8  methods (Access=private)
9  function self=initData(self)
10  import mxberry.conf.test.*;
11  %
12  self.cm=self.factory.getInstance();
13  SConfA=struct('confName','testConfA','alpha',0,'beta',0);
14  SConfB=struct('confName','testConfB','alpha',11,'beta',11);
15  %
16  self.cm.putConf('testConfA',SConfA,0);
17  self.cm.putConf('testConfB',SConfB,0);
18  end
19  end
20  %
21  methods
22  function self = ConfRepoMgrCommonTC(varargin)
23  self = self@matlab.unittest.TestCase(varargin{:});
24  end
25  end
26  %
27  properties (MethodSetupParameter)
28  factoryParam=struct('plain',...
30  'plainver',...
31  mxberry.conf.test.ConfRepoManagerFactory('plainver'),...
32  'adaptivever',...
33  mxberry.conf.test.ConfRepoManagerFactory('adaptivever'),...
34  'adaptive',...
35  mxberry.conf.test.ConfRepoManagerFactory('adaptive'),...
36  'versioned',...
38  end
39  %
40  methods (TestMethodSetup)
41  function self = setUp(self,factoryParam)
42  self.factory=factoryParam;
43  self=self.initData();
44  end
45  end
46  %
47  methods (Test)
48  function self = test_setParamAfterSelect(self)
49  import mxberry.conf.test.*;
50  cm=self.cm; %#ok<*PROP>
51  cm.selectConf('testConfA');
52  valOrig=cm.getParam('alpha');
53  val=valOrig+1;
54  cm.setParam('alpha',val,'writeDepth','cache');
55  cm.selectConf('testConfA','reloadIfSelected',false);
56  self.verifyEqual(val,cm.getParam('alpha'));
57  cm.selectConf('testConfA','reloadIfSelected',true);
58  self.verifyEqual(valOrig,cm.getParam('alpha'));
59  %
60  end
61  function testCacheConf(self)
62  CONF_NAME_LIST={'tstA','tstB','tstC'};
63  cm=self.cm;
64  SConfA=struct('confName','tstA','alpha',0,'beta',0);
65  SConfB=struct('confName','tstB','alpha',2,'beta',2);
66  SMeta.version='3';
67  %
68  cm.putConfToCache('tstA',SConfA,SMeta);
69  checkIfCached([true,false,false]);
70  checkIfSelected([false,false,false]);
71  cm.putConfToCacheAndSelect('tstB',SConfB,SMeta);
72  checkIfCached([true,true,false]);
73  checkIfSelected([false,true,false]);
74  cm.putConfToStorage('tstC',SConfB,SMeta);
75  checkIfCached([true,true,false]);
76  checkIfSelected([false,true,false]);
77  %
78  function checkIfCached(isExpCachedVec)
79  isCachedVec=cellfun(@(x)cm.isCachedConf(x),CONF_NAME_LIST);
80  self.verifyEqual(isExpCachedVec,isCachedVec);
81  end
82  function checkIfSelected(isExpSelectedVec)
83  isSelectedVec=cellfun(@(x)cm.isConfSelected(x),CONF_NAME_LIST);
84  self.verifyEqual(isExpSelectedVec,isSelectedVec);
85  end
86  end
87  end
88 end