Custom metadata configuration
There are properties that can be modified in the environment file of the server that change the way the application functions. QA needs to have UI testing coverage on these areas. However, a problem with this is that once the unit test player starts up and begins executing all UI/unit tests, changes to the environment/properties file will not take effect. Therefore, we need to write our tests in such a way that override what is set in the environment file.
A few examples of flags that affect what we can test in the UI:
Flag Name | Definition | Allowed Values |
---|---|---|
currencyConversionEnabled | Controls whether or not the application currency conversion is enabled or disabled in the environment | #t, #f |
updateAudit | Controls whether update audit is enabled or disabled in the environment | #t, #f |
readAudit | Controls the level of read auditing in the application | "none", "access", "attributes", "values" |
hierarchySecurityEnabled | Controls which security model the application uses | #t, #f |
To modify flags in a .utest, choose from the following methods:
- Parameterize the seeding to change the way the metadata is loaded
- Modify config properties
- Change metadata component initializers
Each one will be discussed in the following information.
Parameterized seeding
- Used for environment file settings that change the way the metadata is loaded (design-time configurable attributes)
- Use this method if an environment file flag requires a database reseed for changes to take effect
The way this method is used is as follows
- Open the .utest file
- Navigate to the Overview tab
- Using the NexJ Studio properties view, Find the properties of the Common (UnitTest) item
In the Value area, add the following
'((flagName . value)).
An example is as follows:CODE'((hierarchySecurityEnabled . #t))
- By saving this, the following is added to the Source tab
<UnitTest properties="'((hierarchySecurityEnabled
. #t))" variables=... >
Using this method, the environment file flag is overridden. Keep in mind, that because changing this flag requires a database recreate to see the changes, the database will recreate when this test is run.
Modifying config properties
This method is mainly used for run-time (not design-time) configurable metadata changes that affect the server at start-up, but are not *.comp properties like audit.
Using this method simply requires adding an additional line to the .utest Initializer in the form of (hashtable-set! sys:config-properties flagName value)
For example, to enable currency conversion in the environment file, we would use
(hashtable-set! sys:config-properties 'currencyConversionEnabled #t)
Changing metadata component initializers
- Used for environment file settings that change the application by accessing *.comp properties
- Used mainly for Audit settings (read/update)
The way these are used is as follows
- Declare two additional global variables in the overview tab:
- one for the *.comp property
- and one for its value.
i.e. componentProperty and componentPropertyInitialValue
In the Initializer, set the componentProperty variable to the corresponding *.comp property found by the invocation context: An example for read audit is shown below:
CODE(set! componentProperty ((((invocation-context)'metadata)'getComponent "System.Auditor")'findPropertyInitializer "readAuditLevel")) ; Return Value ; #<PrimitivePropertyInitializer readAuditLevel>
In the Initializer, set the componentPropertyInitialValue to its initial value (i.e. the value defined in the environment file). This should be done with the invocation context, as we can't always be certain the environment file will not change. To continue with the previous example, we have
CODE(set! componentPropertyInitialValue (componentProperty'value)) ; Return Value ; "none"
Update the componentProperty to its required value.
CODE(componentProperty'value "values") ; Return Value ; ()
Note now that if we were to optionally re-run (componentProperty'value) we would notice that our return value would now change to "values".
Run the unit test.
In the Finalizer, you must reset the defaults. To do so, simply add the following to the Finalizer
CODE(componentProperty'value componentPropertyInitialValue )