Create all Rule Objects for a Session before Running getValue Calculations

Your rule set tests can set up any number of rule objects in a CER session before going on to check any number of calculated values on those rule objects.

However, once calculations have commenced, the RecalculationsProhibited strategy prevents the creation of any rule objects which invalidate the value of a previously-calculated readall calculations.

You should structure your tests so that the creation of all your test rule objects occurs before any calculations (i.e. before any execution of getValue). In practice this is not unduly restrictive.

If your test attempts to create a new rule object in a session after a calculation has occurred, then (if previously-calculated readall calculations are affected), the RecalculationsProhibited strategy will raise a runtime error:

public void newObjectsAddedAfterCalculationsStarted() {

    final FlexibleRetirementYear flexibleRetirementYear =
        FlexibleRetirementYear_Factory.getFactory().newInstance(
            session);

    flexibleRetirementYear.retirementCause().specifyValue(
        "Reached statutory retirement age.");

    /**
     * Calculate the age at retirement and test its value
     */
    CREOLETestHelper.assertEquals(65, flexibleRetirementYear
        .ageAtRetirement().getValue());

    /**
     * Create another rule object.
     */

    /**
     * May not work - new rule objects added to the session once
     * calculations have started could invalidate earlier
     * <code><readall></code> calculations.
     *
     * {@linkplain RecalculationsProhibited} may report the
     * message: "Cannot create new rule objects for this session,
     * because this session has already accepted a calculation
     * request."
     *
     * To avoid this problem, create all your rule objects before
     * attempting any calculations!
     */
    final FlexibleRetirementYear flexibleRetirementYear2 =
        FlexibleRetirementYear_Factory.getFactory().newInstance(
            session);

  }
warning: If your rule set does not currently contain any readall expressions, you might get away with not structuring your tests so that all rule object creation occurs before any calculations.

However, if you change your rule set in the future to contain readall expressions, you would need to restructure your tests at that point.

To avoid rework, always structure your tests so that all rule object creation is performed before calculations begin.