Search in sources :

Example 1 with EntityOwnershipListener

use of org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipListener in project controller by opendaylight.

the class LegacyEntityOwnershipServiceAdapterTest method testRegisterListener.

@Test
public void testRegisterListener() {
    DOMEntityOwnershipListenerRegistration mockDOMReg = mock(DOMEntityOwnershipListenerRegistration.class);
    doNothing().when(mockDOMReg).close();
    doReturn(mockDOMReg).when(mockDOMService).registerListener(eq(DOM_ENTITY.getType()), any(DOMEntityOwnershipListener.class));
    EntityOwnershipListener mockListener = mock(EntityOwnershipListener.class);
    doNothing().when(mockListener).ownershipChanged(any(EntityOwnershipChange.class));
    EntityOwnershipListenerRegistration reg = adapter.registerListener(LEGACY_ENTITY.getType(), mockListener);
    assertNotNull("registerListener returned null", reg);
    assertEquals("getInstance", mockListener, reg.getInstance());
    assertEquals("getEntityType", LEGACY_ENTITY.getType(), reg.getEntityType());
    ArgumentCaptor<DOMEntityOwnershipListener> domListenerCaptor = ArgumentCaptor.forClass(DOMEntityOwnershipListener.class);
    verify(mockDOMService).registerListener(eq(DOM_ENTITY.getType()), domListenerCaptor.capture());
    DOMEntityOwnershipChange domOwnershipChange = new DOMEntityOwnershipChange(DOM_ENTITY, EntityOwnershipChangeState.LOCAL_OWNERSHIP_GRANTED);
    domListenerCaptor.getValue().ownershipChanged(domOwnershipChange);
    ArgumentCaptor<EntityOwnershipChange> ownershipChangeCaptor = ArgumentCaptor.forClass(EntityOwnershipChange.class);
    verify(mockListener).ownershipChanged(ownershipChangeCaptor.capture());
    EntityOwnershipChange change = ownershipChangeCaptor.getValue();
    assertEquals("getEntity", LEGACY_ENTITY, change.getEntity());
    assertEquals("wasOwner", false, change.wasOwner());
    assertEquals("isOwner", true, change.isOwner());
    assertEquals("hasOwner", true, change.hasOwner());
    reg.close();
    verify(mockDOMReg).close();
}
Also used : DOMEntityOwnershipListener(org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipListener) DOMEntityOwnershipListenerRegistration(org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipListenerRegistration) DOMEntityOwnershipChange(org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipChange) EntityOwnershipChange(org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipChange) EntityOwnershipListener(org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipListener) DOMEntityOwnershipListener(org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipListener) DOMEntityOwnershipChange(org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipChange) EntityOwnershipListenerRegistration(org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipListenerRegistration) DOMEntityOwnershipListenerRegistration(org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipListenerRegistration) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)1 EntityOwnershipChange (org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipChange)1 EntityOwnershipListener (org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipListener)1 EntityOwnershipListenerRegistration (org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipListenerRegistration)1 DOMEntityOwnershipChange (org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipChange)1 DOMEntityOwnershipListener (org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipListener)1 DOMEntityOwnershipListenerRegistration (org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipListenerRegistration)1