use of org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipChange 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();
}
Aggregations