use of org.opennms.features.geolocation.api.GeolocationResolver in project opennms by OpenNMS.
the class GeolocationProvisioningAdapterIT method canHandleNullGeolocation.
// See NMS-9187
@Test
public void canHandleNullGeolocation() throws Exception {
// Ensure that the geolocation is null
final OnmsNode node = nodeDao.get(databasePopulator.getNode1().getId());
Assert.assertNull(node.getAssetRecord().getGeolocation());
// Mock the geolocation resolution
final Coordinates coordinates = new Coordinates(-3.179090f, 51.481583f);
final GeolocationResolver geolocationResolverMock = Mockito.mock(GeolocationResolver.class);
Mockito.when(geolocationResolverMock.resolve(Mockito.anyString())).thenReturn(coordinates);
// Manually invoke provisioning adapter
final GeolocationProvisioningAdapter geolocationProvisioningAdapter = new GeolocationProvisioningAdapter();
geolocationProvisioningAdapter.setNodeDao(nodeDao);
geolocationProvisioningAdapter.afterPropertiesSet();
geolocationProvisioningAdapter.updateGeolocation(geolocationResolverMock, node);
// Node should not have been updated
Assert.assertNull(node.getAssetRecord().getGeolocation());
// Set a geolocation and resolve coordinates
node.getAssetRecord().setGeolocation(new OnmsGeolocation());
node.getAssetRecord().getGeolocation().setCity("Cardiff");
nodeDao.saveOrUpdate(node);
geolocationProvisioningAdapter.updateGeolocation(geolocationResolverMock, node);
// Node should have been updated
Assert.assertEquals(coordinates.getLongitude(), node.getAssetRecord().getGeolocation().getLongitude(), 0.001);
Assert.assertEquals(coordinates.getLatitude(), node.getAssetRecord().getGeolocation().getLatitude(), 0.001);
}
Aggregations