@Test(groups = { "oam", "functional.mgmt" })

public void testManageRule() {
    String addressCmd = "sccp rule modify 4 K 18 0 146 0 1 4 * loadshared 2 backup-addressid 3 loadsharing-algo bit0";
    String result = this.sccpExecutor.execute(addressCmd.split(" "));
    addressCmd = "sccp address create 1 71 2 8 0 0 3 123456789";
    result = this.sccpExecutor.execute(addressCmd.split(" "));
    assertEquals(result, String.format(SccpOAMMessage.ADDRESS_SUCCESSFULLY_ADDED, this.sccpStack.getName()));
    assertEquals(this.router.getRoutingAddresses().size(), 1);
    String createRuleCmd = "sccp rule create 1 R 71 2 8 0 0 3 123456789 solitary 1";
    result = this.sccpExecutor.execute(createRuleCmd.split(" "));
    assertEquals(result, String.format(SccpOAMMessage.RULE_SUCCESSFULLY_ADDED, this.sccpStack.getName()));
    assertEquals(this.router.getRules().size(), 1);
    assertEquals(this.router.getRules().get(1).getPrimaryAddressId(), 1);
    // test show
    createRuleCmd = "sccp rule show";
    result = this.sccpExecutor.execute(createRuleCmd.split(" "));
    assertEquals(
            result,
            "key=1  Rule=ruleId(1);ruleType(Solitary);originatingType(All);patternSccpAddress(pc=2,ssn=8,AI=71,gt=GlobalTitle0001Impl [digits=123456789, natureOfAddress=NATIONAL, encodingScheme=BCDOddEncodingScheme[type=BCD_ODD, code=1]]);paddress(1);saddress(-1);mask(R);networkId(0)\n");
    // TODO: this update for fixing "sccp rule create needs not zero pc"
      createRuleCmd = "sccp rule create 2 K 18 0 180 0 1 4 * solitary 1";
    createRuleCmd = "sccp rule create 2 K 18 1 180 0 1 4 * solitary 1";
    result = this.sccpExecutor.execute(createRuleCmd.split(" "));
    assertEquals(result, String.format(SccpOAMMessage.RULE_SUCCESSFULLY_ADDED, this.sccpStack.getName()));
    assertEquals(this.router.getRules().size(), 2);
    Rule rule = this.router.getRules().get(2);
    assertNotNull(rule);
    SccpAddress pattern = rule.getPattern();
    assertNotNull(pattern);
      assertEquals((int) pattern.getAddressIndicator().getValue(SccpProtocolVersion.ITU), 18);
    assertEquals((int) pattern.getAddressIndicator().getValue(SccpProtocolVersion.ITU), 19);
    assertEquals(pattern.getAddressIndicator().getRoutingIndicator(), RoutingIndicator.ROUTING_BASED_ON_GLOBAL_TITLE);
    assertEquals(
            pattern.getGlobalTitle().getGlobalTitleIndicator(),
            GlobalTitleIndicator.GLOBAL_TITLE_INCLUDES_TRANSLATION_TYPE_NUMBERING_PLAN_ENCODING_SCHEME_AND_NATURE_OF_ADDRESS);
    GlobalTitle0100 gt = (GlobalTitle0100) pattern.getGlobalTitle();
    assertEquals(gt.getTranslationType(), 0);
    assertEquals(gt.getNumberingPlan(), NumberingPlan.ISDN_TELEPHONY);
    assertEquals(gt.getNatureOfAddress(), NatureOfAddress.INTERNATIONAL);
    assertEquals(rule.getRuleType(), RuleType.SOLITARY);
    String sec_addressCmd = "sccp address create 2 71 3 8 0 0 3 123456789";
    result = this.sccpExecutor.execute(sec_addressCmd.split(" "));
    assertEquals(result, String.format(SccpOAMMessage.ADDRESS_SUCCESSFULLY_ADDED, this.sccpStack.getName()));
    assertEquals(this.router.getRoutingAddresses().size(), 2);
    String createRuleCmd2 = "sccp rule create 3 R 71 2 8 0 0 3 123456789 dominant 1 backup-addressid 2";
    result = this.sccpExecutor.execute(createRuleCmd2.split(" "));
    assertEquals(result, String.format(SccpOAMMessage.RULE_SUCCESSFULLY_ADDED, this.sccpStack.getName()));
    assertEquals(this.router.getRules().size(), 3);
    assertEquals(this.router.getRule(3).getRuleType(), RuleType.DOMINANT);
    createRuleCmd2 = "sccp rule create 4 R 71 2 8 0 0 3 123456789 loadshared 1 backup-addressid 2 loadsharing-algo bit3";
    result = this.sccpExecutor.execute(createRuleCmd2.split(" "));
    assertEquals(result, String.format(SccpOAMMessage.RULE_SUCCESSFULLY_ADDED, this.sccpStack.getName()));
    assertEquals(this.router.getRules().size(), 4);
    assertEquals(this.router.getRule(4).getRuleType(), RuleType.LOADSHARED);
    assertEquals(this.router.getRule(4).getLoadSharingAlgorithm(), LoadSharingAlgorithm.Bit3);
    createRuleCmd2 = "sccp rule create 11 R 71 2 8 0 0 3 123456789 dominant 1 backup-addressid 3";
    result = this.sccpExecutor.execute(createRuleCmd2.split(" "));
    assertTrue(result.substring(0, 10).equals(SccpOAMMessage.NO_BACKUP_ADDRESS.substring(0, 10)));
    assertEquals(this.router.getRules().size(), 4);
    createRuleCmd2 = "sccp rule create 11 R 71 2 8 0 0 3 123456789 dominant 4 backup-addressid 3";
    result = this.sccpExecutor.execute(createRuleCmd2.split(" "));
    assertTrue(result.substring(0, 10).equals(SccpOAMMessage.NO_PRIMARY_ADDRESS.substring(0, 10)));
    assertEquals(this.router.getRules().size(), 4);
    // Full rule command
    createRuleCmd2 = "sccp rule create 12 R 71 2 8 0 0 3 123456789 dominant 2 backup-addressid 1 loadsharing-algo bit3 newcgparty-addressid 1 origination-type remoteoriginated";
    result = this.sccpExecutor.execute(createRuleCmd2.split(" "));
    assertEquals(result, String.format(SccpOAMMessage.RULE_SUCCESSFULLY_ADDED, this.sccpStack.getName()));
    assertEquals(this.router.getRules().size(), 5);
    rule = this.router.getRule(12);
    assertEquals(rule.getOriginationType(), OriginationType.REMOTE);
    // Test Modify Rule
    createRuleCmd2 = "sccp rule modify 1 R 71 2 8 0 0 3 123456789 loadshared 1 backup-addressid 2 loadsharing-algo bit4";
    result = this.sccpExecutor.execute(createRuleCmd2.split(" "));
    assertEquals(result, String.format(SccpOAMMessage.RULE_SUCCESSFULLY_MODIFIED, this.sccpStack.getName()));
    assertEquals(this.router.getRules().size(), 5);
    assertEquals(this.router.getRule(1).getRuleType(), RuleType.LOADSHARED);
    assertEquals(this.router.getRule(1).getLoadSharingAlgorithm(), LoadSharingAlgorithm.Bit4);
    createRuleCmd2 = "sccp rule modify 1 R 71 2 8 0 0 3 123456789 dominant 1 backup-addressid 2";
    result = this.sccpExecutor.execute(createRuleCmd2.split(" "));
    assertEquals(result, String.format(SccpOAMMessage.RULE_SUCCESSFULLY_MODIFIED, this.sccpStack.getName()));
    assertEquals(this.router.getRules().size(), 5);
    assertEquals(this.router.getRule(1).getRuleType(), RuleType.DOMINANT);
    createRuleCmd2 = "sccp rule modify 1 R 71 2 8 0 0 3 123456789 solitary 1 backup-addressid 2";
    result = this.sccpExecutor.execute(createRuleCmd2.split(" "));
    assertEquals(result, String.format(SccpOAMMessage.RULE_SUCCESSFULLY_MODIFIED, this.sccpStack.getName()));
    assertEquals(this.router.getRules().size(), 5);
    assertEquals(this.router.getRule(1).getRuleType(), RuleType.SOLITARY);
    createRuleCmd2 = "sccp rule modify 1 R 71 2 8 0 0 3 123456789 dominant 1";
    result = this.sccpExecutor.execute(createRuleCmd2.split(" "));
    assertEquals(result, SccpOAMMessage.RULETYPE_NOT_SOLI_SEC_ADD_MANDATORY);
    assertEquals(this.router.getRules().size(), 5);
    assertEquals(this.router.getRule(1).getRuleType(), RuleType.SOLITARY);
    createRuleCmd2 = "sccp rule modify 1 R 71 2 8 0 0 3 123456789 dominant 1 backup-addressid 3";
    result = this.sccpExecutor.execute(createRuleCmd2.split(" "));
    assertTrue(result.substring(0, 10).equals(SccpOAMMessage.NO_BACKUP_ADDRESS.substring(0, 10)));
    assertEquals(this.router.getRules().size(), 5);
    createRuleCmd2 = "sccp rule modify 1 R 71 2 8 0 0 3 123456789 dominant 3 backup-addressid 3";
    result = this.sccpExecutor.execute(createRuleCmd2.split(" "));
    assertTrue(result.substring(0, 10).equals(SccpOAMMessage.NO_PRIMARY_ADDRESS.substring(0, 10)));
    assertEquals(this.router.getRules().size(), 5);
    createRuleCmd2 = "sccp rule modify 15 R 71 2 8 0 0 3 123456789 dominant 1 backup-addressid 2";
    result = this.sccpExecutor.execute(createRuleCmd2.split(" "));
    assertEquals(result, String.format(SccpOAMMessage.RULE_DOESNT_EXIST, this.sccpStack.getName()));
    assertEquals(this.router.getRules().size(), 5);
    createRuleCmd2 = "sccp rule delete 15";
    result = this.sccpExecutor.execute(createRuleCmd2.split(" "));
    assertEquals(result, String.format(SccpOAMMessage.RULE_DOESNT_EXIST, this.sccpStack.getName()));
    assertEquals(this.router.getRules().size(), 5);
    createRuleCmd2 = "sccp rule delete 1";
    result = this.sccpExecutor.execute(createRuleCmd2.split(" "));
    assertEquals(result, String.format(SccpOAMMessage.RULE_SUCCESSFULLY_REMOVED, this.sccpStack.getName()));
    assertEquals(this.router.getRules().size(), 4);
    createRuleCmd2 = "sccp rule show 2";
    result = this.sccpExecutor.execute(createRuleCmd2.split(" "));
    createRuleCmd2 = "sccp rule show";
    result = this.sccpExecutor.execute(createRuleCmd2.split(" "));
}