Loading...
Searching...
No Matches
mpe_checkrestore.test.sas
Go to the documentation of this file.
1/**
2 @file
3 @brief Testing mpe_checkrestore macro
4 @details Checking functionality of mpe_checkrestore.sas macro
5
6 <h4> SAS Macros </h4>
7 @li dc_getsettings.sas
8 @li mpe_checkrestore.sas
9 @li mp_assert.sas
10 @li mp_assertscope.sas
11 @li mx_execute.sas
12
13
14 @author 4GL Apps Ltd
15 @copyright 4GL Apps Ltd. This code may only be used within Data Controller
16 and may not be re-distributed or re-sold without the express permission of
17 4GL Apps Ltd.
18
19**/
20
21/* Settings first: dc_getsettings fetches the app's settings.sas through the
22 drive API, and after the two %mx_execute calls below that fetch comes back
23 empty - 'Cannot open %INCLUDE file SETTINGS.' - which aborts the test before
24 its assertions run. Nothing in the staging needs it. */
25%global dc_repo_users dc_macros dc_libref dc_staging_area dc_admin_group
26 mpelib dc_dttmtfmt;
27%dc_getsettings()
28
29/* Change the table here rather than calling postdata.test.1: the id of the
30 submission is what this test asks about, and only the call that stages the
31 data knows it. Reading it back from MPE_SUBMIT means guessing which row the
32 previous run left behind, which is what made a repeated run ask about a
33 submission that had already been restored. */
34data work.sascontroltable;
35 action='LOAD';
36 message="checkrestore prep";
37 libds="&dclib..MPE_X_TEST";
38 output;
39 stop;
40run;
41
42proc sql noprint;
43 select max(primary_key_field) into: maxpk
44 from &dclib..mpe_x_test;
45quit;
46
47data work.jsdata;
48 set &dclib..mpe_x_test(rename=(
49 some_date=dt2 some_datetime=dttm2 some_time=tm2)
50 );
51 /* the adapter sends these as strings */
52 some_date=put(dt2,date9.);
53 some_datetime=put(dttm2,datetime19.);
54 some_time=put(tm2,time.);
55 drop dt2 dttm2 tm2;
56 if _n_=1 then do;
57 _____DELETE__THIS__RECORD_____='Yes';
58 output;
59 _____DELETE__THIS__RECORD_____='No';
60 /* modify one record and add more */
61 do primary_key_field=&maxpk to (&maxpk+5);
62 some_num=ranuni(0);
63 output;
64 end;
65 end;
66 else stop;
67run;
68
69%mx_execute(&appLoc/services/editors/stagedata,
70 viyacontext=&defaultcontext,
71 inputdatasets=work.jsdata work.sascontroltable,
72 outlib=web1,
73 mdebug=0
74)
75
76%let dsid=0;
77data _null_;
78 set web1.sasparams;
79 call symputx('dsid',dsid);
80run;
81%mp_assert(
82 iftrue=(&dsid ne 0),
83 desc=Checking the change was staged
84)
85
86/* approve it, so there is a submission with an audit trail to restore */
87data work.sascontroltable;
88 ACTION='APPROVE_TABLE';
89 TABLE="&dsid";
90 /* difftime is numeric for approve action */
91 DIFFTIME="%sysfunc(datetime())";
92 output;
93 stop;
94run;
95%mx_execute(&appLoc/services/auditors/postdata,
96 viyacontext=&defaultcontext,
97 inputdatasets=work.sascontroltable,
98 outlib=web3,
99 outref=wb3,
100 mdebug=0
101)
102%let approved=0;
103data _null_;
104 set web3.apparams;
105 if response='SUCCESS!' then call symputx('approved',1);
106run;
107%mp_assert(
108 iftrue=(&approved=1),
109 desc=Checking the submission was approved
110)
111
112%let loadref=&dsid.;
113
114
115%put checking it is restorable;
116%mp_assertscope(SNAPSHOT)
117%mpe_checkrestore(&loadref,outresult=ALLOW_RESTORE,outreason=REASON)
118%mp_assertscope(COMPARE,
119 desc=Checking macro variables against previous snapshot,
120 ignorelist=ALLOW_RESTORE REASON
121 MC0_JADP1LEN MC0_JADP2LEN MC0_JADP3LEN MC0_JADPNUM MC0_JADVLEN
122)
123
124%mp_assert(
125 iftrue=(&syscc=0),
126 desc=Checking successful submission
127)
128%mp_assert(
129 iftrue=(&ALLOW_RESTORE=YES),
130 desc=Checking restoring is possible
131)
132%mp_assert(
133 iftrue=(&REASON=IS ADMIN),
134 desc=Checking reason code returned
135)