Search in sources :

Example 1 with GeolocationResolver

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);
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) Coordinates(org.opennms.features.geolocation.api.Coordinates) GeolocationResolver(org.opennms.features.geolocation.api.GeolocationResolver) OnmsGeolocation(org.opennms.netmgt.model.OnmsGeolocation) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)1 Coordinates (org.opennms.features.geolocation.api.Coordinates)1 GeolocationResolver (org.opennms.features.geolocation.api.GeolocationResolver)1 OnmsGeolocation (org.opennms.netmgt.model.OnmsGeolocation)1 OnmsNode (org.opennms.netmgt.model.OnmsNode)1