A tourist of IMi9 migration

根据team的要去,我以

testcase test() runs on CSysAdapterMtc system CSysAdapterTestSystem {  
    var charstring scfFileName := "ApplyDelta2x3ChainRmodChange_SCF.xml";
    var charstring deltaFileName := "ApplyDelta2x3ChainRmodChange_CDNL.xml";
    var cablnkOperations expectedCablnks := {
        {"/BBMOD_A-1", omit, "/RMOD_A-2", omit, omit},
        {"/RMOD_A-2", omit, "/RMOD_A-5", omit, omit},
        {"/RMOD_A-5", omit, "/PHYANT_A-19", omit, omit} } 

    prepareTest(scfFileName);
    copyDeltas({deltaFileName});

    bm.stop;
    bm.start(startupFromScfAndTriggerDeltaConversionImi9(deltaFileName, expectedCablnks));
    bm.done;

    bm.start(MBm.waitForPoweroff());
    setverdict(pass);

    MSysAdapterMtcFunctions.tearDownTestcase();
}   

The testcase itself is very simple, it started a bm function to receive expected message and the case is pass when bm component is done.

bm.stop;
bm.start(startupFromScfAndTriggerDeltaConversionImi9(deltaFileName, expectedCablnks));
bm.done;

We don't need to update testcase body, but in order to separate with old bm function startupFromScfAndTriggerDeltaConversion, I renamed it to startupFromScfAndTriggerDeltaConversionImi9.

In function startupFromScfAndTriggerDeltaConversionImi9 populateAndStoreIfValidated is invoked firstly.

and in function populateAndStoreIfValidated we want to receive IMChangeRequest message, that what we need to rework.

Function before rework

function populateAndStoreIfValidated(in boolean validated := true) runs on CBm {
    MBm.init();
    registerInfoModelInCcs();
    executeScfPopulate();

    var IMChangeRequest changeRequest;
    var address sender_;

    if (validated == true) {
        mInfoModelPort.receive(SCFValidatedRequest) -> value changeRequest sender sender_;
        processChangeRequest(changeRequest, sender_);

        var object_t scfMo := MBm.getMo(NP1_SCF_DISTNAME);
        scfMo.object.scf.oper_store := {storeMode := EStoreMode_NewFile};
        triggerInternalObjectExecute(scfMo);
    }
    else {
        mInfoModelPort.receive(SCFInvalidRequest) -> value changeRequest sender sender_;
        processChangeRequest(changeRequest, sender_);
    }
}

`

After migration, it should like below

function populateAndStoreIfValidatedImi9(in boolean validated := true) runs on CBm {

    MBm.init();
    registerInfoModelInCcs();
    executeScfPopulateImi9();

    var IMChangeRequest changeRequest;
    var address sender_;

    if (validated == true) {
        /*
        mInfoModelPort.receive(SCFValidatedRequest) -> value changeRequest sender sender_;
        processChangeRequest(changeRequest, sender_);

        var object_t scfMo := MBm.getMo(NP1_SCF_DISTNAME);
        scfMo.object.scf.oper_store := {storeMode := EStoreMode_NewFile};
        triggerInternalObjectExecute(scfMo);
        */
        single(scf_event(
            dn := "/MRBTS-1/RAT-1/BTS_L-1/BTS_CONF-1/NP-1/SCF-1",
            obj := SCFValidatedRequestObect,
            act := op_execute_act({{
                distname := "on_matched",
                object := {scf := scf_oper_store}}},
                "scf oper_store is triggered")
        ));
    }
    else {
        /*
        mInfoModelPort.receive(SCFInvalidRequest) -> value changeRequest sender sender_;
        processChangeRequest(changeRequest, sender_);
        */
        single(scf_event(
            dn := "/MRBTS-1/RAT-1/BTS_L-1/BTS_CONF-1/NP-1/SCF-1",
            obj := SCFValidatedRequestObect,
            act := log_act("scf proceduralState updated to invalid")
        ))
    }
}

`
The test logic is still unchanged but receive is replaced by new API single.

it's not always so easy like above, sometime we need to rewrite whole function like what i did to function matchCablnks. Function matchCablnks compared the case input with received message, but we can't checked the message anymore when IMi9 is used, what should we do? We need to rewrite the case with new expectation. We create new expectation according fuction input and pass them to new APIs. See example below

before migration

    /*get received message*/
    receivedOperations := handleFakeDelta(deltaFilename, createNp2ObjectsRequest);
    /*compare received message with case input*/
    matchCablnks(cablnks, receivedOperations);

after migration

function matchCablnks(
        cablnkOperations cablnks ) runs on CBm {

    log("enter checkCablnks");
    var integer cablnkIt, cablnkCount := lengthof(cablnks);
    var boolean errorsOccurred := false;
    var template RoEvent expectedEvents := {};

    for (cablnkIt := 0; cablnkIt < cablnkCount; cablnkIt := cablnkIt + 1)
    {
        var cablnkAttribs cab := cablnks[cablnkIt];
        var boolean cablnkFound;

        template protoObjects.cablnk_a_t.linkMode modeOmit := omit;
        template integer intOmit := omit;
        var template cablnk_a_t object := cablnk_a_any;

        if (match (cab.mode, modeOmit) or match (cab.sourcePort, intOmit) or match (cab.destPort, intOmit)) {

            object := topologyCablnk(cab.source, cab.destination);
        }
        else {
            object := topologyCablnk(cab.source, cab.destination);
        }

        expectedEvents[cablnkIt] := cablnk_a_event(
            dnt := ".*/CABLNK_A-.*",
            obj := object,
            act := log_act("creatation event is matched")
        )
    }

    interleaved(expectedEvents);
}

`

你可能感兴趣的:(A tourist of IMi9 migration)