SccpExecutor implements ShellExecutor { private String manageAddress(String[] options) throws Exception { if (options.length < 3) { return SccpOAMMessage.INVALID_COMMAND; } String command = options[2]; if (command == null) { return SccpOAMMessage.INVALID_COMMAND; } if (command.equals("create")) { if (options.length < 4) { return SccpOAMMessage.INVALID_COMMAND; } int addressId = Integer.parseInt(options[3]); int count = 11; while (count < options.length) { String key = options[count++]; if (key == null) { return SccpOAMMessage.INVALID_COMMAND; } if (key.equals("stackname")) { String m3uaStackName = options[count++]; SccpStackImpl sccpStaclImpl = this.sccpStacks.get(m3uaStackName); if (sccpStaclImpl == null) { return String.format(SccpOAMMessage.NO_SCCP_MANAGEMENT_BEAN_FOR_NAME, m3uaStackName); } this.sccpStack = sccpStaclImpl; } else { return SccpOAMMessage.INVALID_COMMAND; } } this.setDefaultValue(); SccpAddress address = this.createAddress(options, 4, false); this.sccpStack.getRouter().addRoutingAddress(addressId, address); return String.format(SccpOAMMessage.ADDRESS_SUCCESSFULLY_ADDED, this.sccpStack.getName()); } else if (command.equals("modify")) { if (options.length < 4) { return SccpOAMMessage.INVALID_COMMAND; } int addressId = Integer.parseInt(options[3]); int count = 11; while (count < options.length) { String key = options[count++]; if (key == null) { return SccpOAMMessage.INVALID_COMMAND; } if (key.equals("stackname")) { String m3uaStackName = options[count++]; SccpStackImpl sccpStaclImpl = this.sccpStacks.get(m3uaStackName); if (sccpStaclImpl == null) { return String.format(SccpOAMMessage.NO_SCCP_MANAGEMENT_BEAN_FOR_NAME, m3uaStackName); } this.sccpStack = sccpStaclImpl; } else { return SccpOAMMessage.INVALID_COMMAND; } } this.setDefaultValue(); SccpAddress address = this.createAddress(options, 4, false); this.sccpStack.getRouter().modifyRoutingAddress(addressId, address); return String.format(SccpOAMMessage.ADDRESS_SUCCESSFULLY_MODIFIED, this.sccpStack.getName()); } else if (command.equals("delete")) { if (options.length < 4) { return SccpOAMMessage.INVALID_COMMAND; } int addressId = Integer.parseInt(options[3]); int count = 4; while (count < options.length) { String key = options[count++]; if (key == null) { return SccpOAMMessage.INVALID_COMMAND; } if (key.equals("stackname")) { String m3uaStackName = options[count++]; SccpStackImpl sccpStaclImpl = this.sccpStacks.get(m3uaStackName); if (sccpStaclImpl == null) { return String.format(SccpOAMMessage.NO_SCCP_MANAGEMENT_BEAN_FOR_NAME, m3uaStackName); } this.sccpStack = sccpStaclImpl; } else { return SccpOAMMessage.INVALID_COMMAND; } } this.setDefaultValue(); this.sccpStack.getRouter().removeRoutingAddress(addressId); return String.format(SccpOAMMessage.ADDRESS_SUCCESSFULLY_DELETED, this.sccpStack.getName()); } else if (command.equals("show")) { int count = 3; int addressId = -1; while (count < options.length) { String key = options[count++]; if (key == null) { return SccpOAMMessage.INVALID_COMMAND; } if (key.equals("stackname")) { String m3uaStackName = options[count++]; SccpStackImpl sccpStaclImpl = this.sccpStacks.get(m3uaStackName); if (sccpStaclImpl == null) { return String.format(SccpOAMMessage.NO_SCCP_MANAGEMENT_BEAN_FOR_NAME, m3uaStackName); } this.sccpStack = sccpStaclImpl; } else if (key.equals("id")) { addressId = Integer.parseInt(options[count++]); } else { return SccpOAMMessage.INVALID_COMMAND; } } this.setDefaultValue(); if (addressId != -1) { SccpAddress pa = this.sccpStack.getRouter().getRoutingAddress(addressId); if (pa == null) { return String.format(SccpOAMMessage.ADDRESS_DOESNT_EXIST, this.sccpStack.getName()); } return pa.toString(); } if (this.sccpStack.getRouter().getRoutingAddresses().size() == 0) { return String.format(SccpOAMMessage.ADDRESS_DOESNT_EXIST, this.sccpStack.getName()); } StringBuffer sb = new StringBuffer(); Map<Integer, SccpAddress> idVsPrimAdd = this.sccpStack.getRouter().getRoutingAddresses(); for (Integer e : idVsPrimAdd.keySet()) { SccpAddress address = idVsPrimAdd.get(e); sb.append("key="); sb.append(e); sb.append(" "); sb.append(address); sb.append("\n"); } return sb.toString(); } return SccpOAMMessage.INVALID_COMMAND; } SccpExecutor(); void setSccpStacks(Map<String, SccpStackImpl> sccpStacksTemp); Map<String, SccpStackImpl> getSccpStacks(); String execute(String[] options); @Override boolean handles(String command);  }
@Test(groups = { "oam", "functional.mgmt" }) public void testManageAddress() { String prim_addressCmd = "sccp address create 1 71 6535 8 0 0 12 93707100007"; String result = this.sccpExecutor.execute(prim_addressCmd.split(" ")); assertEquals(result, String.format(SccpOAMMessage.ADDRESS_SUCCESSFULLY_ADDED, this.sccpStack.getName())); assertEquals(this.router.getRoutingAddresses().size(), 1); prim_addressCmd = "sccp address show"; result = this.sccpExecutor.execute(prim_addressCmd.split(" ")); assertEquals(result, "key=1 pc=6535,ssn=8,AI=71,gt=GlobalTitle0001Impl [digits=93707100007, natureOfAddress=SPARE_12, encodingScheme=BCDOddEncodingScheme[type=BCD_ODD, code=1]]\n"); }