when(fetcherRegistry.getSelectedFetcherIndex("fetcher.comment")).thenReturn(3);
when(fetcherRegistry.getSelectedFetcherIndex("noSuchFetcher")).thenReturn(-1);
ScanningResultList scanningResults = new ScanningResultList(fetcherRegistry);
scanningResults.initNewScan(mockFeeder("info"));
ScanningResult result = scanningResults.createResult(InetAddress.getByName("127.0.0.1"));
result.setValue(0, new InetAddressHolder(InetAddress.getByName("127.0.0.1")));
result.setValue(1, "HOSTNAME");
result.setValue(2, new IntegerWithUnit(10, "ms"));
scanningResults.registerAtIndex(0, result);
OpenerLauncher ol = new OpenerLauncher(fetcherRegistry, scanningResults);
assertEquals("\\\\127.0.0.1", ol.prepareOpenerStringForItem("\\\\${fetcher.ip}", 0));
assertEquals("HOSTNAME$$$127.0.0.1xxx${}", ol.prepareOpenerStringForItem("${fetcher.hostname}$$$${fetcher.ip}xxx${}", 0));
assertEquals("http://127.0.0.1:80/www", ol.prepareOpenerStringForItem("http://${fetcher.ip}:80/www", 0));
assertEquals(result.getValues().get(2) + ", xx", ol.prepareOpenerStringForItem("${fetcher.ping}, xx", 0));
try {
ol.prepareOpenerStringForItem("${noSuchFetcher}", 0);
fail();
}
catch (UserErrorException e) {
assertEquals(Labels.getLabel("exception.UserErrorException.opener.unknownFetcher") + "noSuchFetcher", e.getMessage());
}
try {
ol.prepareOpenerStringForItem("${fetcher.comment}", 0);
fail();
}
catch (UserErrorException e) {
assertEquals(Labels.getLabel("exception.UserErrorException.opener.nullFetcherValue") + "fetcher.comment", e.getMessage());
}
try {
result.setValue(3, NotAvailable.VALUE);
ol.prepareOpenerStringForItem("${fetcher.comment}", 0);
fail();
}
catch (UserErrorException e) {
assertEquals(Labels.getLabel("exception.UserErrorException.opener.nullFetcherValue") + "fetcher.comment", e.getMessage());
}
result.setValue(1, null);
assertEquals("Hostname opening should fall back to the IP", "127.0.0.1", ol.prepareOpenerStringForItem("${" + HostnameFetcher.ID + "}", 0));
result.setValue(1, NotAvailable.VALUE);
assertEquals("Hostname opening should fall back to the IP", "127.0.0.1", ol.prepareOpenerStringForItem("${" + HostnameFetcher.ID + "}", 0));
}