### Question:
NeLocationProvider implements ClusteredDataTreeChangeListener<NetworkElements>, AutoCloseable { @VisibleForTesting synchronized List<AddressEndpoint> getEndpoints() { return endpoints; } NeLocationProvider(DataBroker dataBroker); @Override void close(); synchronized void onEndpointsChange(Collection<DataTreeModification<AddressEndpoint>> changes); @Override synchronized void onDataTreeChanged(Collection<DataTreeModification<NetworkElements>> changes); static final String NE_LOCATION_PROVIDER_NAME; }### Answer:
@Test public void test_AddressEndpointWrite_NoNE_NoOverwrite() throws Exception { AddressEndpoint endpoint = writeBaseAddrEndpoint(); List<AddressEndpoint> endpoints = neProvider.getEndpoints(); assertEquals(1, endpoints.size()); assertEquals(endpoint, endpoints.get(0)); verifyEmptyLocations(); }
@Test public void test_AddressEndpointWrite_NoNE_Overwrite() throws Exception { writeBaseAddrEndpoint(); NetworkContainment nc = new NetworkContainmentBuilder().setContainment( new NetworkDomainContainmentBuilder().setNetworkDomainId(new NetworkDomainId(L3_CONTEXT_ID)).build()) .build(); AddressEndpoint endpoint = new AddressEndpointBuilder().setKey( new AddressEndpointKey(IP_V4_HOST_ADDRESS_1, IpPrefixType.class, new ContextId(L3_CONTEXT_ID), L3Context.class)).setNetworkContainment(nc).setTenant(TENANT).setEndpointGroup(DEFAULT_EPG).build(); InstanceIdentifier<AddressEndpoint> iid = IidFactory.addressEndpointIid(endpoint.getKey()); WriteTransaction wtx = dataBroker.newWriteOnlyTransaction(); wtx.put(LogicalDatastoreType.OPERATIONAL, iid, endpoint, true); wtx.submit().get(); List<AddressEndpoint> endpoints = neProvider.getEndpoints(); assertEquals(1, endpoints.size()); assertEquals(endpoint, endpoints.get(0)); verifyEmptyLocations(); }
@Test public void test_AddressEndpointModified_NoNE() throws Exception { writeBaseAddrEndpoint(); NetworkContainment nc = new NetworkContainmentBuilder().setContainment( new NetworkDomainContainmentBuilder().setNetworkDomainId(new NetworkDomainId(L3_CONTEXT_ID)).build()) .build(); InstanceIdentifier<NetworkContainment> iid = InstanceIdentifier .builder(Endpoints.class) .child(AddressEndpoints.class) .child(AddressEndpoint.class, new AddressEndpointKey(IP_V4_HOST_ADDRESS_1, IpPrefixType.class, new ContextId(L3_CONTEXT_ID), L3Context.class)) .child(NetworkContainment.class) .build(); WriteTransaction wtx = dataBroker.newWriteOnlyTransaction(); wtx.put(LogicalDatastoreType.OPERATIONAL, iid, nc); wtx.submit().get(); List<AddressEndpoint> l3Endpoint = neProvider.getEndpoints(); assertEquals(1, l3Endpoint.size()); assertNotNull(l3Endpoint.get(0).getNetworkContainment()); assertEquals(nc, l3Endpoint.get(0).getNetworkContainment()); verifyEmptyLocations(); }
@Test public void test_EndpointsDelete_NoNE() throws Exception { writeBaseAddrEndpoint(); InstanceIdentifier<Endpoints> iid = InstanceIdentifier.builder(Endpoints.class) .build(); WriteTransaction wtx = dataBroker.newWriteOnlyTransaction(); wtx.delete(LogicalDatastoreType.OPERATIONAL, iid); wtx.submit().get(); List<AddressEndpoint> l3Endpoint = neProvider.getEndpoints(); assertEquals(0, l3Endpoint.size()); verifyEmptyLocations(); }
@Test public void test_EndpointsModify_NoNE() throws Exception { writeBaseAddrEndpoint(); InstanceIdentifier<Endpoints> iid = InstanceIdentifier.builder(Endpoints.class) .build(); WriteTransaction wtx = dataBroker.newWriteOnlyTransaction(); wtx.delete(LogicalDatastoreType.OPERATIONAL, iid); wtx.submit().get(); List<AddressEndpoint> l3Endpoint = neProvider.getEndpoints(); assertEquals(0, l3Endpoint.size()); verifyEmptyLocations(); }