class SccpExecutor implements ShellExecutor {

    public String execute(String[] options) {
        if (this.sccpStacks.size() == 0) {
            logger.warn("SCCP stack not set. Command will not be executed ");
            return SccpOAMMessage.SERVER_ERROR;
        }

        // Atleast 1 option is passed?
        if (options == null || options.length < 2) {
            return SccpOAMMessage.INVALID_COMMAND;
        }

        String firstOption = options[1];

        if (firstOption == null) {
            return SccpOAMMessage.INVALID_COMMAND;
        }

        try {
            if (firstOption.equals("rule")) {
                return this.manageRule(options);
            } else if (firstOption.equals("address")) {
                return this.manageAddress(options);
            } else if (firstOption.equals("rsp")) {
                return this.manageRsp(options);
            } else if (firstOption.equals("rss")) {
                return this.manageRss(options);
            } else if (firstOption.equals("lmr")) {
                return this.manageLmr(options);
            } else if (firstOption.equals("sap")) {
                return this.manageSap(options);
            } else if (firstOption.equals("dest")) {
                return this.manageDest(options);
            } else if (firstOption.equals("csp")) {
                return this.manageConcernedSpc(options);
            } else if (firstOption.equals("set")) {
                return this.manageSet(options);
            } else if (firstOption.equals("get")) {
                return this.manageGet(options);
            }
            // } catch (Exception e) {
            // logger.error(String.format("Error while executing comand %s", Arrays.toString(options)), e);
            // return e.getMessage();
        } catch (Throwable t) {
            logger.error(String.format("Error while executing comand %s", Arrays.toString(options)), t);
            return t.getMessage();
        }

        return SccpOAMMessage.INVALID_COMMAND;
    }

}

class SccpExecutorTest {

    private Router router;
    private SccpResource sccpResource;
    private SccpStackImpl sccpStack;
    private SccpExecutor sccpExecutor;

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

    public void testRss() {

        String rspCmd = "sccp rss create 2 11 8 0";
        String res = this.sccpExecutor.execute(rspCmd.split(" "));
        assertEquals(this.sccpResource.getRemoteSsns().size(), 1);
        RemoteSubSystem rss = this.sccpResource.getRemoteSsn(2);
        assertEquals(rss.getRemoteSpc(), 11);
        assertEquals(rss.getRemoteSsn(), 8);
        assertFalse(rss.getMarkProhibitedWhenSpcResuming());

        // Test show
        rspCmd = "sccp rss show";
        res = this.sccpExecutor.execute(rspCmd.split(" "));
        assertEquals(res, "key=2  rsp=11 rss=8 rss-flag=0 rss-prohibited=false\n");

        rspCmd = "sccp rss delete 5";
        res = this.sccpExecutor.execute(rspCmd.split(" "));
        assertEquals(res, String.format(SccpOAMMessage.RSS_DOESNT_EXIST, this.sccpStack.getName()));
        assertEquals(this.sccpResource.getRemoteSsns().size(), 1);
        rss = this.sccpResource.getRemoteSsn(2);
        assertEquals(rss.getRemoteSpc(), 11);

        rspCmd = "sccp rss delete 2";
        res = this.sccpExecutor.execute(rspCmd.split(" "));
        assertEquals(this.sccpResource.getRemoteSsns().size(), 0);

        rspCmd = "sccp rss create 2 12 8 0 prohibitedwhenspcresuming true";
        res = this.sccpExecutor.execute(rspCmd.split(" "));
        assertEquals(res, String.format(SccpOAMMessage.RSS_SUCCESSFULLY_ADDED, this.sccpStack.getName()));
        assertEquals(this.sccpResource.getRemoteSsns().size(), 1);
        rss = this.sccpResource.getRemoteSsn(2);
        assertEquals(rss.getRemoteSpc(), 12);
        assertEquals(rss.getRemoteSsn(), 8);
        assertTrue(rss.getMarkProhibitedWhenSpcResuming());

        rspCmd = "sccp rss create 2 12 8 0";
        res = this.sccpExecutor.execute(rspCmd.split(" "));
        assertTrue(res.equals(SccpOAMMessage.RSS_ALREADY_EXIST));
        assertEquals(this.sccpResource.getRemoteSsns().size(), 1);
        rss = this.sccpResource.getRemoteSsn(2);
        assertEquals(rss.getRemoteSpc(), 12);
        assertEquals(rss.getRemoteSsn(), 8);
        assertTrue(rss.getMarkProhibitedWhenSpcResuming());

        rspCmd = "sccp rss modify 2 13 18 0";
        res = this.sccpExecutor.execute(rspCmd.split(" "));
        assertEquals(this.sccpResource.getRemoteSsns().size(), 1);
        rss = this.sccpResource.getRemoteSsn(2);
        assertEquals(rss.getRemoteSpc(), 13);
        assertEquals(rss.getRemoteSsn(), 18);
        assertFalse(rss.getMarkProhibitedWhenSpcResuming());

        rspCmd = "sccp rss modify 2 14 19 0 prohibitedwhenspcresuming true";
        res = this.sccpExecutor.execute(rspCmd.split(" "));
        assertEquals(res, String.format(SccpOAMMessage.RSS_SUCCESSFULLY_MODIFIED, this.sccpStack.getName()));
        assertEquals(this.sccpResource.getRemoteSsns().size(), 1);
        rss = this.sccpResource.getRemoteSsn(2);
        assertEquals(rss.getRemoteSpc(), 14);
        assertEquals(rss.getRemoteSsn(), 19);
        assertTrue(rss.getMarkProhibitedWhenSpcResuming());

        rspCmd = "sccp rss modify 3 15 19 0 prohibitedwhenspcresuming true";
        res = this.sccpExecutor.execute(rspCmd.split(" "));
        assertEquals(res, String.format(SccpOAMMessage.RSS_DOESNT_EXIST, this.sccpStack.getName()));
        assertEquals(this.sccpResource.getRemoteSsns().size(), 1);
        rss = this.sccpResource.getRemoteSsn(2);
        assertEquals(rss.getRemoteSpc(), 14);
        assertEquals(rss.getRemoteSsn(), 19);
        assertTrue(rss.getMarkProhibitedWhenSpcResuming());

        rspCmd = "sccp rss show 1";
        res = this.sccpExecutor.execute(rspCmd.split(" "));

        rspCmd = "sccp rss show 2";
        res = this.sccpExecutor.execute(rspCmd.split(" "));

        rspCmd = "sccp rss show";
        res = this.sccpExecutor.execute(rspCmd.split(" "));
    }

}