@Test
public void testSwitchEventsWithNotification() 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");
monitorable.setNewStatusVariableValue("sv.id1", "15");
Event[] 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));
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));
monitorAdmin.switchEvents("com.acme.pid/sv.id1", false);
osgiVisitor.cleanPostedEvents();
monitorable.setNewStatusVariableValue("sv.id1", "25");
events = osgiVisitor.getPostedEvents();
Assert.assertEquals(0, events.length);
monitorAdmin.switchEvents("com.acme.pid/sv.id1", true);
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));
Assert.assertEquals("sv.id1", events[0].getProperty(ConstantsMonitorAdmin.MON_STATUSVARIABLE_NAME));