Package org.knowhowlab.osgi.monitoradmin.mocks

Examples of org.knowhowlab.osgi.monitoradmin.mocks.MockMonitorable


    @Test
    public void testStartJob() throws Exception {
        HashMap<ServiceReference, Monitorable> map = new HashMap<ServiceReference, Monitorable>();

        MockMonitorable monitorable = new MockMonitorable();

        StatusVariable[] statusVariables = {
                new StatusVariable("sv.id1", StatusVariable.CM_CC, 0),
                new StatusVariable("sv.id2", StatusVariable.CM_CC, "test")
        };
        monitorable.setStatusVariables(statusVariables);
        monitorable.setNotificationSupport("sv.id1", true);

        map.put(new MonitorableMockServiceReference("com.acme.pid"), monitorable);
        osgiVisitor.setReferences(map);

        MonitorAdmin monitorAdmin = new MonitorAdminImpl(logVisitor, common, bundle);

        monitorable.setListener(common);
        monitorable.setMonitorableId("com.acme.pid");

        try {
            monitorAdmin.startJob("init1", new String[]{"com.acme.pid/sv.id11"}, 1);
            Assert.fail();
        } catch (IllegalArgumentException e) {
        }

        try {
            monitorAdmin.startJob("init1", new String[]{"com.acme.pid/sv.id2"}, 1);
            Assert.fail();
        } catch (IllegalArgumentException e) {
        }

        try {
            monitorAdmin.startJob(null, new String[]{"com.acme.pid/sv.id2"}, 1);
            Assert.fail();
        } catch (IllegalArgumentException e) {
        }

        try {
            monitorAdmin.startJob("init1", new String[]{"com.acme.pid1/sv.id1"}, 1);
            Assert.fail();
        } catch (IllegalArgumentException e) {
        }

        try {
            monitorAdmin.startJob("init1", new String[]{"com.acme.pid/sv.id1"}, -1);
            Assert.fail();
        } catch (IllegalArgumentException e) {
        }

        MonitoringJob job = monitorAdmin.startJob("init1", new String[]{"com.acme.pid/sv.id1"}, 1);

        MonitoringJob[] jobs = monitorAdmin.getRunningJobs();
        Assert.assertEquals(1, jobs.length);

        monitorable.setNewStatusVariableValue("sv.id1", "15");

        Event[] events = osgiVisitor.getPostedEvents();
        Assert.assertEquals(2, events.length);
        Assert.assertEquals(ConstantsMonitorAdmin.TOPIC, events[0].getTopic());
        Assert.assertEquals("com.acme.pid", events[0].getProperty(ConstantsMonitorAdmin.MON_MONITORABLE_PID));
        Assert.assertEquals("sv.id1", events[0].getProperty(ConstantsMonitorAdmin.MON_STATUSVARIABLE_NAME));
        Assert.assertEquals("15", events[0].getProperty(ConstantsMonitorAdmin.MON_STATUSVARIABLE_VALUE));
        Assert.assertNull(events[0].getProperty(ConstantsMonitorAdmin.MON_LISTENER_ID));

        Assert.assertEquals(ConstantsMonitorAdmin.TOPIC, events[1].getTopic());
        Assert.assertEquals("com.acme.pid", events[1].getProperty(ConstantsMonitorAdmin.MON_MONITORABLE_PID));
        Assert.assertEquals("sv.id1", events[1].getProperty(ConstantsMonitorAdmin.MON_STATUSVARIABLE_NAME));
        Assert.assertEquals("15", events[1].getProperty(ConstantsMonitorAdmin.MON_STATUSVARIABLE_VALUE));
        Assert.assertEquals("init1", events[1].getProperty(ConstantsMonitorAdmin.MON_LISTENER_ID));

        job.stop();
        jobs = monitorAdmin.getRunningJobs();
        Assert.assertEquals(0, jobs.length);

        osgiVisitor.cleanPostedEvents();

        monitorable.setNewStatusVariableValue("sv.id1", "25");

        events = osgiVisitor.getPostedEvents();
        Assert.assertEquals(1, events.length);
        Assert.assertEquals(ConstantsMonitorAdmin.TOPIC, events[0].getTopic());
        Assert.assertEquals("com.acme.pid", events[0].getProperty(ConstantsMonitorAdmin.MON_MONITORABLE_PID));
View Full Code Here


    @Test
    public void testStartScheduledJob() throws Exception {
        HashMap<ServiceReference, Monitorable> map = new HashMap<ServiceReference, Monitorable>();

        MockMonitorable monitorable = new MockMonitorable();

        StatusVariable[] statusVariables = {
                new StatusVariable("sv.id1", StatusVariable.CM_CC, 0),
                new StatusVariable("sv.id2", StatusVariable.CM_CC, "test")
        };
        monitorable.setStatusVariables(statusVariables);

        map.put(new MonitorableMockServiceReference("com.acme.pid"), monitorable);
        osgiVisitor.setReferences(map);

        MonitorAdmin monitorAdmin = new MonitorAdminImpl(logVisitor, common, bundle);

        monitorable.setListener(common);
        monitorable.setMonitorableId("com.acme.pid");

        monitorable.setNewStatusVariableValue("sv.id1", "15");

        try {
            monitorAdmin.startScheduledJob("init1", new String[]{"com.acme.pid/sv.id11"}, 1, 1);
            Assert.fail();
        } catch (IllegalArgumentException e) {
        }

        try {
            monitorAdmin.startScheduledJob("init1", new String[]{"com.acme.pid1/sv.id1"}, 1, 1);
            Assert.fail();
        } catch (IllegalArgumentException e) {
        }

        try {
            monitorAdmin.startScheduledJob(null, new String[]{"com.acme.pid1/sv.id1"}, 1, 1);
            Assert.fail();
        } catch (IllegalArgumentException e) {
        }

        try {
            monitorAdmin.startScheduledJob("init1", new String[]{"com.acme.pid/sv.id1"}, -1, 1);
            Assert.fail();
        } catch (IllegalArgumentException e) {
        }

        try {
            monitorAdmin.startScheduledJob("init1", new String[]{"com.acme.pid/sv.id1"}, 1, -1);
            Assert.fail();
        } catch (IllegalArgumentException e) {
        }

        MonitoringJob job = monitorAdmin.startScheduledJob("init1", new String[]{"com.acme.pid/sv.id1"}, 5, 0);

        MonitoringJob[] jobs = monitorAdmin.getRunningJobs();
        Assert.assertEquals(1, jobs.length);

        TimeUnit.SECONDS.sleep(7);

        Event[] events = osgiVisitor.getPostedEvents();
        Assert.assertEquals(2, events.length);
        Assert.assertEquals(ConstantsMonitorAdmin.TOPIC, events[0].getTopic());
        Assert.assertEquals("com.acme.pid", events[0].getProperty(ConstantsMonitorAdmin.MON_MONITORABLE_PID));
        Assert.assertEquals("sv.id1", events[0].getProperty(ConstantsMonitorAdmin.MON_STATUSVARIABLE_NAME));
        Assert.assertEquals("15", events[0].getProperty(ConstantsMonitorAdmin.MON_STATUSVARIABLE_VALUE));
        Assert.assertEquals("init1", events[0].getProperty(ConstantsMonitorAdmin.MON_LISTENER_ID));

        job.stop();
        jobs = monitorAdmin.getRunningJobs();
        Assert.assertEquals(0, jobs.length);

        osgiVisitor.cleanPostedEvents();

        monitorable.setNewStatusVariableValue("sv.id1", "25");

        events = osgiVisitor.getPostedEvents();
        Assert.assertEquals(0, events.length);
    }
View Full Code Here

TOP

Related Classes of org.knowhowlab.osgi.monitoradmin.mocks.MockMonitorable

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.