Published on :
Unit Test CREATION_INTERNE

Unit Test of SASjs mv_webout and mp_assert macros

This code is also available in: Deutsch Español Français
Awaiting validation
This program performs a series of unit tests:
1. Simulation of an incoming web request (FETCH) via macro variables and verification of the resulting table via `mp_assertdsobs`.
2. Generation of a complex JSON stream (Arrays and Objects) to a temporary physical file via `mv_webout`.
3. Rereading of the generated JSON file using the `LIBNAME JSON` engine to validate the integrity and structure of the produced data.
Data Analysis

Type : CREATION_INTERNE


All data is simulated within the script (DATA step, macro variables) or generated by the tested macros.

1 Code Block
DATA STEP
Explanation :
Test environment initialization: definition of macro variables simulating data received from a web request (SASjs format).
Copied!
1DATA _null_;
2 call symputx('sasjs1data','area:$char4.'!!'0d0a'x!!'Adak');
3 call symputx('sasjs_tables','areas');
4RUN;
5%put &=sasjs1data;
2 Code Block
MACRO CALL Data
Explanation :
Execution of the FETCH macro and assertion to validate that the 'work.areas' table was created with exactly one observation.
Copied!
1%mv_webout(FETCH)
2 
3%mp_assertdsobs(work.areas,
4 desc=Test INPUT TABLE has 1 row,
5 test=EQUALS 1,
6 outds=work.test_results
7)
3 Code Block
MACRO CALL Data
Explanation :
JSON output generation test: creation of dummy data and writing to a temporary file via the OPEN, ARR (Array), OBJ (Object) and CLOSE commands of mv_webout.
Copied!
1%let fref=%mf_getuniquefileref();
2%global _metaperson;
3DATA some datasets;
4 x=1;
5RUN;
6%mv_webout(OPEN,fref=&fref,stream=N)
7%mv_webout(ARR,some,fref=&fref,stream=N)
8%mv_webout(OBJ,datasets,fref=&fref,stream=N)
9%mv_webout(CLOSE,fref=&fref,stream=N)
4 Code Block
DATA STEP
Explanation :
Validation of the produced JSON file: display of raw content in the log, parsing via the LIBNAME JSON engine, and final assertion to compare retrieved values.
Copied!
1DATA _null_;
2 INFILE &fref;
3 INPUT;
4 putlog _infile_;
5RUN;
6 
7LIBNAME test JSON (&fref);
8DATA root;
9 SET test.root;
10 call symputx('checkval',sysvlong);
11RUN;
12DATA alldata;
13 SET test.alldata;
14RUN;
15 
16%mp_assert(
17 iftrue=(%str(&checkval)=%str(&sysvlong)),
18 desc=Check IF the sysvlong value was created
19)
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.