Search in sources :

Example 1 with DOMDataTreeChangeListener

use of org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeListener in project controller by opendaylight.

the class LegacyDOMDataBrokerAdapterTest method testDataTreeChangeListener.

@SuppressWarnings("unchecked")
@Test
public void testDataTreeChangeListener() {
    DOMDataTreeChangeService domDTCLService = (DOMDataTreeChangeService) adapter.getSupportedExtensions().get(DOMDataTreeChangeService.class);
    assertNotNull("DOMDataTreeChangeService not found", domDTCLService);
    ArgumentCaptor<org.opendaylight.mdsal.dom.api.DOMDataTreeChangeListener> storeDTCL = ArgumentCaptor.forClass(org.opendaylight.mdsal.dom.api.DOMDataTreeChangeListener.class);
    ListenerRegistration<org.opendaylight.mdsal.dom.api.DOMDataTreeChangeListener> mockReg = mock(ListenerRegistration.class);
    doNothing().when(mockReg).close();
    doAnswer(invocation -> storeDTCL.getValue()).when(mockReg).getInstance();
    doReturn(mockReg).when(mockConfigStore).registerTreeChangeListener(eq(TestModel.TEST_PATH), storeDTCL.capture());
    DOMDataTreeChangeListener brokerDTCL = mock(DOMDataTreeChangeListener.class);
    ListenerRegistration<DOMDataTreeChangeListener> reg = domDTCLService.registerDataTreeChangeListener(new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH), brokerDTCL);
    assertEquals("getInstance", brokerDTCL, reg.getInstance());
    Collection<DataTreeCandidate> changes = Arrays.asList(mock(DataTreeCandidate.class));
    storeDTCL.getValue().onDataTreeChanged(changes);
    verify(brokerDTCL).onDataTreeChanged(changes);
    reg.close();
    verify(mockReg).close();
    // Test ClusteredDOMDataTreeChangeListener
    ArgumentCaptor<org.opendaylight.mdsal.dom.api.DOMDataTreeChangeListener> storeClusteredDTCL = ArgumentCaptor.forClass(org.opendaylight.mdsal.dom.api.DOMDataTreeChangeListener.class);
    mockReg = mock(ListenerRegistration.class);
    doReturn(mockReg).when(mockConfigStore).registerTreeChangeListener(eq(TestModel.TEST_PATH), storeClusteredDTCL.capture());
    final ClusteredDOMDataTreeChangeListener brokerClusteredDTCL = mock(ClusteredDOMDataTreeChangeListener.class);
    domDTCLService.registerDataTreeChangeListener(new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH), brokerClusteredDTCL);
    assertTrue("Expected ClusteredDOMDataTreeChangeListener: " + storeClusteredDTCL.getValue(), storeClusteredDTCL.getValue() instanceof org.opendaylight.mdsal.dom.api.ClusteredDOMDataTreeChangeListener);
    storeClusteredDTCL.getValue().onDataTreeChanged(changes);
    verify(brokerClusteredDTCL).onDataTreeChanged(changes);
}
Also used : DOMDataTreeIdentifier(org.opendaylight.controller.md.sal.dom.api.DOMDataTreeIdentifier) ListenerRegistration(org.opendaylight.yangtools.concepts.ListenerRegistration) DataTreeCandidate(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate) DOMDataTreeChangeService(org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeService) DOMDataTreeChangeListener(org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeListener) ClusteredDOMDataTreeChangeListener(org.opendaylight.controller.md.sal.dom.api.ClusteredDOMDataTreeChangeListener) ClusteredDOMDataTreeChangeListener(org.opendaylight.controller.md.sal.dom.api.ClusteredDOMDataTreeChangeListener) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)1 ClusteredDOMDataTreeChangeListener (org.opendaylight.controller.md.sal.dom.api.ClusteredDOMDataTreeChangeListener)1 DOMDataTreeChangeListener (org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeListener)1 DOMDataTreeChangeService (org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeService)1 DOMDataTreeIdentifier (org.opendaylight.controller.md.sal.dom.api.DOMDataTreeIdentifier)1 ListenerRegistration (org.opendaylight.yangtools.concepts.ListenerRegistration)1 DataTreeCandidate (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate)1