From 1e41e1e66043ce3a7ffff6e71ba9aa61fd376bb7 Mon Sep 17 00:00:00 2001 From: angryziber Date: Wed, 13 Jun 2007 21:19:15 +0000 Subject: [PATCH] starting to merge several separate projects back into one: no more separate unit tests and swt git-svn-id: https://ipscan.svn.sourceforge.net/svnroot/ipscan/trunk@126 375186e5-ef17-0410-b0b6-91563547dcda --- .../src/net/azib/ipscan/MainTest.java | 48 ----- .../net/azib/ipscan/config/ConfigTest.java | 26 --- .../ipscan/config/DimensionsConfigTest.java | 64 ------ .../net/azib/ipscan/config/LabelsTest.java | 138 ------------- .../azib/ipscan/config/LoggerFactoryTest.java | 22 -- .../ipscan/config/NamedListConfigTest.java | 93 --------- .../azib/ipscan/config/OpenersConfigTest.java | 128 ------------ .../ipscan/core/InetAddressUtilsTest.java | 101 ---------- .../azib/ipscan/core/IntegerWithUnitTest.java | 57 ------ .../azib/ipscan/core/PortIteratorTest.java | 48 ----- .../src/net/azib/ipscan/core/ScannerTest.java | 148 -------------- .../ipscan/core/ScanningResultListTest.java | 189 ------------------ .../ipscan/core/net/ICMPSharedPingerTest.java | 29 --- .../core/net/PingerRegistryImplTest.java | 49 ----- .../core/values/NotAvailableValueTest.java | 37 ---- .../core/values/NotScannedValueTest.java | 38 ---- .../core/values/NumericListValueTest.java | 30 --- .../exporters/AbstractExporterTestCase.java | 145 -------------- .../ipscan/exporters/CSVExporterTest.java | 52 ----- .../ipscan/exporters/ExportProcessorTest.java | 112 ----------- .../exporters/ExporterRegistryTest.java | 60 ------ .../ipscan/exporters/IPListExporterTest.java | 87 -------- .../ipscan/exporters/TXTExporterTest.java | 70 ------- .../ipscan/exporters/XMLExporterTest.java | 98 --------- .../azib/ipscan/feeders/FeederTestUtils.java | 23 --- .../azib/ipscan/feeders/FileFeederTest.java | 127 ------------ .../azib/ipscan/feeders/RandomFeederTest.java | 144 ------------- .../azib/ipscan/feeders/RangeFeederTest.java | 99 --------- .../fetchers/AbstractFetcherTestCase.java | 38 ---- .../fetchers/FetcherRegistryImplTest.java | 107 ---------- .../ipscan/fetchers/HostnameFetcherTest.java | 39 ---- .../azib/ipscan/fetchers/IPFetcherTest.java | 34 ---- .../azib/ipscan/fetchers/PingFetcherTest.java | 22 -- .../ipscan/fetchers/PingTTLFetcherTest.java | 22 -- .../ipscan/fetchers/PortsFetcherTest.java | 22 -- .../ipscan/gui/SelectFetchersDialogTest.java | 35 ---- .../gui/actions/OpenerLauncherTest.java | 76 ------- .../gui/feeders/AbstractFeederGUITest.java | 63 ------ .../ext/easymock/easymock.jar | Bin {ipscan-unittest => ipscan}/ext/emma/emma.jar | Bin .../ext/emma/emma_ant.jar | Bin .../ext/junit/junit-4.1.jar | Bin {swt => ipscan/ext/swt}/swt-gtk.jar | Bin {swt => ipscan/ext/swt}/swt-mac.jar | Bin {swt => ipscan/ext/swt}/swt-win32.jar | Bin 45 files changed, 2720 deletions(-) delete mode 100755 ipscan-unittest/src/net/azib/ipscan/MainTest.java delete mode 100755 ipscan-unittest/src/net/azib/ipscan/config/ConfigTest.java delete mode 100755 ipscan-unittest/src/net/azib/ipscan/config/DimensionsConfigTest.java delete mode 100755 ipscan-unittest/src/net/azib/ipscan/config/LabelsTest.java delete mode 100755 ipscan-unittest/src/net/azib/ipscan/config/LoggerFactoryTest.java delete mode 100755 ipscan-unittest/src/net/azib/ipscan/config/NamedListConfigTest.java delete mode 100755 ipscan-unittest/src/net/azib/ipscan/config/OpenersConfigTest.java delete mode 100755 ipscan-unittest/src/net/azib/ipscan/core/InetAddressUtilsTest.java delete mode 100755 ipscan-unittest/src/net/azib/ipscan/core/IntegerWithUnitTest.java delete mode 100755 ipscan-unittest/src/net/azib/ipscan/core/PortIteratorTest.java delete mode 100755 ipscan-unittest/src/net/azib/ipscan/core/ScannerTest.java delete mode 100755 ipscan-unittest/src/net/azib/ipscan/core/ScanningResultListTest.java delete mode 100755 ipscan-unittest/src/net/azib/ipscan/core/net/ICMPSharedPingerTest.java delete mode 100755 ipscan-unittest/src/net/azib/ipscan/core/net/PingerRegistryImplTest.java delete mode 100755 ipscan-unittest/src/net/azib/ipscan/core/values/NotAvailableValueTest.java delete mode 100755 ipscan-unittest/src/net/azib/ipscan/core/values/NotScannedValueTest.java delete mode 100755 ipscan-unittest/src/net/azib/ipscan/core/values/NumericListValueTest.java delete mode 100755 ipscan-unittest/src/net/azib/ipscan/exporters/AbstractExporterTestCase.java delete mode 100755 ipscan-unittest/src/net/azib/ipscan/exporters/CSVExporterTest.java delete mode 100755 ipscan-unittest/src/net/azib/ipscan/exporters/ExportProcessorTest.java delete mode 100755 ipscan-unittest/src/net/azib/ipscan/exporters/ExporterRegistryTest.java delete mode 100755 ipscan-unittest/src/net/azib/ipscan/exporters/IPListExporterTest.java delete mode 100755 ipscan-unittest/src/net/azib/ipscan/exporters/TXTExporterTest.java delete mode 100755 ipscan-unittest/src/net/azib/ipscan/exporters/XMLExporterTest.java delete mode 100755 ipscan-unittest/src/net/azib/ipscan/feeders/FeederTestUtils.java delete mode 100755 ipscan-unittest/src/net/azib/ipscan/feeders/FileFeederTest.java delete mode 100755 ipscan-unittest/src/net/azib/ipscan/feeders/RandomFeederTest.java delete mode 100755 ipscan-unittest/src/net/azib/ipscan/feeders/RangeFeederTest.java delete mode 100755 ipscan-unittest/src/net/azib/ipscan/fetchers/AbstractFetcherTestCase.java delete mode 100755 ipscan-unittest/src/net/azib/ipscan/fetchers/FetcherRegistryImplTest.java delete mode 100755 ipscan-unittest/src/net/azib/ipscan/fetchers/HostnameFetcherTest.java delete mode 100755 ipscan-unittest/src/net/azib/ipscan/fetchers/IPFetcherTest.java delete mode 100755 ipscan-unittest/src/net/azib/ipscan/fetchers/PingFetcherTest.java delete mode 100755 ipscan-unittest/src/net/azib/ipscan/fetchers/PingTTLFetcherTest.java delete mode 100755 ipscan-unittest/src/net/azib/ipscan/fetchers/PortsFetcherTest.java delete mode 100755 ipscan-unittest/src/net/azib/ipscan/gui/SelectFetchersDialogTest.java delete mode 100755 ipscan-unittest/src/net/azib/ipscan/gui/actions/OpenerLauncherTest.java delete mode 100755 ipscan-unittest/src/net/azib/ipscan/gui/feeders/AbstractFeederGUITest.java rename {ipscan-unittest => ipscan}/ext/easymock/easymock.jar (100%) rename {ipscan-unittest => ipscan}/ext/emma/emma.jar (100%) rename {ipscan-unittest => ipscan}/ext/emma/emma_ant.jar (100%) rename {ipscan-unittest => ipscan}/ext/junit/junit-4.1.jar (100%) rename {swt => ipscan/ext/swt}/swt-gtk.jar (100%) rename {swt => ipscan/ext/swt}/swt-mac.jar (100%) rename {swt => ipscan/ext/swt}/swt-win32.jar (100%) diff --git a/ipscan-unittest/src/net/azib/ipscan/MainTest.java b/ipscan-unittest/src/net/azib/ipscan/MainTest.java deleted file mode 100755 index 0cdc1a8f..00000000 --- a/ipscan-unittest/src/net/azib/ipscan/MainTest.java +++ /dev/null @@ -1,48 +0,0 @@ -package net.azib.ipscan; - -import static org.junit.Assert.*; - -import java.util.logging.Handler; -import java.util.logging.LogRecord; - -import org.junit.Test; - -import net.azib.ipscan.config.Labels; -import net.azib.ipscan.feeders.FeederException; - -public class MainTest { - - @Test - public void getLocalizedMessage() { - // unknown exception - final boolean wasStackTraceLogged[] = {false}; - Throwable e = new Exception("hello, test!"); - Main.LOG.setUseParentHandlers(false); - Main.LOG.addHandler(new Handler() { - public void close() throws SecurityException { - } - public void flush() { - } - public void publish(LogRecord record) { - wasStackTraceLogged[0] = true; - } - }); - assertEquals(e.toString(), Main.getLocalizedMessage(e)); - assertTrue(wasStackTraceLogged[0]); - - // localized exception - assertEquals(Labels.getLabel("exception.FeederException.range.greaterThan"), - Main.getLocalizedMessage(new FeederException("range.greaterThan"))); - - // message-less localized exception - assertEquals(Labels.getLabel("exception.OutOfMemoryError"), - Main.getLocalizedMessage(new OutOfMemoryError())); - } - - @Test - public void classShortName() { - assertEquals("String", Main.getClassShortName(String.class)); - assertEquals("MainTest", Main.getClassShortName(MainTest.class)); - } - -} diff --git a/ipscan-unittest/src/net/azib/ipscan/config/ConfigTest.java b/ipscan-unittest/src/net/azib/ipscan/config/ConfigTest.java deleted file mode 100755 index eec8cf32..00000000 --- a/ipscan-unittest/src/net/azib/ipscan/config/ConfigTest.java +++ /dev/null @@ -1,26 +0,0 @@ -/** - * - */ -package net.azib.ipscan.config; - -import static org.junit.Assert.assertNotNull; - -import org.junit.BeforeClass; -import org.junit.Test; - -/** - * @author anton - */ -public class ConfigTest { - - @BeforeClass - public static void globalSetUp() throws Exception { - Config.initialize(); - } - - @Test - public void testInitialize() { - assertNotNull(Config.getPreferences()); - assertNotNull(Config.getGlobal()); - } -} diff --git a/ipscan-unittest/src/net/azib/ipscan/config/DimensionsConfigTest.java b/ipscan-unittest/src/net/azib/ipscan/config/DimensionsConfigTest.java deleted file mode 100755 index 5db7297f..00000000 --- a/ipscan-unittest/src/net/azib/ipscan/config/DimensionsConfigTest.java +++ /dev/null @@ -1,64 +0,0 @@ -/** - * - */ -package net.azib.ipscan.config; - -import static org.junit.Assert.assertEquals; - -import java.util.prefs.Preferences; - -import org.eclipse.swt.graphics.Rectangle; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -/** - * DimensionsConfigTest - * - * @author anton - */ -public class DimensionsConfigTest { - - private Preferences preferences; - private DimensionsConfig config; - - @Before - public void setUp() throws Exception { - preferences = Preferences.userRoot().node("ipscan-test"); - preferences.clear(); - config = new DimensionsConfig(preferences); - } - - @After - public void tearDown() throws Exception { - preferences.removeNode(); - } - - @Test - public void getWindowDimensions() throws Exception { - config.windowHeight = 1; - config.windowWidth = 2; - config.windowTop = 3; - config.windowLeft = 4; - assertEquals(new Rectangle(4, 3, 2, 1), config.getWindowBounds()); - } - - @Test - public void store() throws Exception { - config.setWindowBounds(new Rectangle(11, 22, 33, 44), false); - config.store(); - assertEquals(11, preferences.getInt("windowLeft", 0)); - - config.setWindowBounds(new Rectangle(77, 22, 33, 44), true); - config.store(); - assertEquals(11, preferences.getInt("windowLeft", 0)); - } - - @Test - public void columnWidths() throws Exception { - config.setColumnWidth("ABC", 35); - assertEquals(35, config.getColumnWidth("ABC")); - assertEquals(35, preferences.getInt("columnWidth.ABC", 0)); - } - -} diff --git a/ipscan-unittest/src/net/azib/ipscan/config/LabelsTest.java b/ipscan-unittest/src/net/azib/ipscan/config/LabelsTest.java deleted file mode 100755 index 3a6ad1b0..00000000 --- a/ipscan-unittest/src/net/azib/ipscan/config/LabelsTest.java +++ /dev/null @@ -1,138 +0,0 @@ -package net.azib.ipscan.config; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; -import java.io.IOException; -import java.io.InputStream; -import java.util.Locale; -import java.util.MissingResourceException; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import junit.framework.AssertionFailedError; - -import org.junit.Before; -import org.junit.Test; - -public class LabelsTest { - - @Before - public void setUp() throws Exception { - // Labels should initialize themselves on first load - } - - @Test - public void testReinitialize() { - Labels.initialize(new Locale("en")); - Object oldInternalInstance = Labels.getInstance(); - Labels.initialize(new Locale("en")); - assertTrue(oldInternalInstance == Labels.getInstance()); - } - - @Test - public void testInitialize() { - Labels.initialize(new Locale("en")); - Object oldInternalInstance = Labels.getInstance(); - Labels.initialize(new Locale("ee")); - assertFalse(oldInternalInstance == Labels.getInstance()); - } - - @Test - public void testSimpleLabel() { - assertEquals("&File", Labels.getLabel("menu.file")); - } - - @Test - public void testInexistentLabel() { - try { - Labels.getLabel("abra-cadabra"); - fail(); - } - catch (Exception e) { - // exception is good - } - } - - @Test - public void testImageAsStream() throws IOException { - InputStream stream = Labels.getInstance().getImageAsStream("button.start.img"); - // Now check the first bytes of GIF image header - stream.read(); - assertEquals((int)'P', stream.read()); - assertEquals((int)'N', stream.read()); - assertEquals((int)'G', stream.read()); - stream.close(); - } - - /** - * This test recursively processes all source files and tries - * to resolve every label it finds. - */ - @Test - public void testAllLabels() throws IOException { - File srcDir = new File("../ipscan/src"); - recurseAndTestLabels(srcDir); - } - - private void recurseAndTestLabels(File dir) throws IOException { - String files[] = dir.list(); - for (int i = 0; i < files.length; i++) { - File file = new File(dir, files[i]); - if (file.isDirectory()) { - recurseAndTestLabels(file); - } - else - if (file.getName().endsWith(".java")) { - findAndTestLabels(file); - } - } - } - - private void findAndTestLabels(File file) throws IOException { - // TODO: tune these regexps - final Pattern LABELS_REGEX = Pattern.compile("Label.{1,60}\"([a-z]\\w+?\\.[a-z][\\w.]+?)\""); - final Pattern EXCEPTION_REGEX = Pattern.compile("new\\s+?(\\w+?Exception)\\(\"([\\w.]+?)\""); - - BufferedReader fileReader = new BufferedReader(new FileReader(file)); - StringBuffer sb = new StringBuffer(); - String fileLine; - while ((fileLine = fileReader.readLine()) != null) { - sb.append(fileLine); - } - fileReader.close(); - String fileContent = sb.toString(); - - String key = null; -// String value = null; - try { -// System.out.println(file.getPath()); - - Matcher matcher = LABELS_REGEX.matcher(fileContent); - while (matcher.find()) { - // try to load the label - key = matcher.group(1); -// value = - Labels.getLabel(key); -// System.out.println(key + "=" + value); - } - - matcher = EXCEPTION_REGEX.matcher(fileContent); - while (matcher.find()) { - // try to load the label - key = "exception." + matcher.group(1) + "." + matcher.group(2); -// value = - Labels.getLabel(key); -// System.out.println(key + "=" + value); - } - } - catch (MissingResourceException e) { - throw new AssertionFailedError("Label not found: " + key + ", in file: " + file.getPath()); - } - } -} diff --git a/ipscan-unittest/src/net/azib/ipscan/config/LoggerFactoryTest.java b/ipscan-unittest/src/net/azib/ipscan/config/LoggerFactoryTest.java deleted file mode 100755 index 270fa30c..00000000 --- a/ipscan-unittest/src/net/azib/ipscan/config/LoggerFactoryTest.java +++ /dev/null @@ -1,22 +0,0 @@ -/** - * - */ -package net.azib.ipscan.config; - -import java.util.logging.Logger; - -import junit.framework.TestCase; - -/** - * @author Anton Keks - */ -public class LoggerFactoryTest extends TestCase { - - private static Logger staticLogger = LoggerFactory.getLogger(); - - public void testAutomaticNameInitialization() { - assertEquals(getClass().getName(), staticLogger.getName()); - assertEquals(getClass().getName(), LoggerFactory.getLogger().getName()); - } - -} diff --git a/ipscan-unittest/src/net/azib/ipscan/config/NamedListConfigTest.java b/ipscan-unittest/src/net/azib/ipscan/config/NamedListConfigTest.java deleted file mode 100755 index 69fbd11f..00000000 --- a/ipscan-unittest/src/net/azib/ipscan/config/NamedListConfigTest.java +++ /dev/null @@ -1,93 +0,0 @@ -/** - * - */ -package net.azib.ipscan.config; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; - -import java.util.Iterator; -import java.util.prefs.Preferences; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -/** - * NamedListConfigTest - * - * @author anton - */ -public class NamedListConfigTest { - - private static final String PREFERENCE_NAME = "blah"; - private Preferences preferences; - private NamedListConfig config; - - @Before - public void setUp() throws Exception { - preferences = Preferences.userRoot().node("ipscan-test"); - preferences.node(PREFERENCE_NAME).clear(); - config = new NamedListConfig(preferences, PREFERENCE_NAME); - } - - @After - public void tearDown() throws Exception { - preferences.removeNode(); - } - - @Test - public void testAdd() { - config.add("Mega favorite", "aaa:xxx"); - assertEquals("aaa:xxx", config.get("Mega favorite")); - assertEquals(1, config.size()); - } - - @Test - public void testLoad() throws Exception { - preferences.put(PREFERENCE_NAME, "aa###aaa###bb###bbb###cc###ccc"); - NamedListConfig config = new NamedListConfig(preferences, PREFERENCE_NAME); - - assertEquals("aaa", config.get("aa")); - assertEquals("bbb", config.get("bb")); - assertEquals("ccc", config.get("cc")); - assertEquals(3, config.size()); - } - - @Test @SuppressWarnings("unchecked") - public void testOrder() throws Exception { - preferences.put(PREFERENCE_NAME, "aa###aaa###bb###bbb###cc###ccc"); - NamedListConfig config = new NamedListConfig(preferences, PREFERENCE_NAME); - - Iterator namesIterator = config.iterateNames(); - assertEquals("aa", namesIterator.next()); - assertEquals("bb", namesIterator.next()); - assertEquals("cc", namesIterator.next()); - assertFalse(namesIterator.hasNext()); - } - - @Test - public void testStore() throws Exception { - config.add("x", "y"); - config.add("Buga muga x,1,2,3,4,5", "opopo op : , . l ; - # | @@"); - config.add("127.0.0.1", "192.168.2.25"); - config.store(); - - assertEquals("x###y###Buga muga x,1,2,3,4,5###opopo op : , . l ; - # | @@###127.0.0.1###192.168.2.25", preferences.get(PREFERENCE_NAME, "")); - } - - @Test @SuppressWarnings("unchecked") - public void testUpdate() { - config.add("z", "zzz"); - config.add("y", "yyy"); - config.add("x", "xxx"); - - config.update(new String[] {"x", "z"}); - - Iterator i = config.iterateNames(); - assertEquals("xxx", config.get((String)i.next())); - assertEquals("zzz", config.get((String)i.next())); - assertFalse(i.hasNext()); - } - -} diff --git a/ipscan-unittest/src/net/azib/ipscan/config/OpenersConfigTest.java b/ipscan-unittest/src/net/azib/ipscan/config/OpenersConfigTest.java deleted file mode 100755 index 10dbbff8..00000000 --- a/ipscan-unittest/src/net/azib/ipscan/config/OpenersConfigTest.java +++ /dev/null @@ -1,128 +0,0 @@ -/** - * - */ -package net.azib.ipscan.config; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import java.io.File; -import java.util.Iterator; -import java.util.prefs.Preferences; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -/** - * OpenersConfigTest - * - * @author anton - */ -public class OpenersConfigTest { - - private static final String PREFERENCE_NAME = "openers"; - private Preferences preferences; - private OpenersConfig config; - - @Before - public void setUp() throws Exception { - preferences = Preferences.userRoot().node("ipscan-test"); - preferences.clear(); - config = new OpenersConfig(preferences); - } - - @After - public void tearDown() throws Exception { - preferences.removeNode(); - } - - @Test - public void testDefaultValues() throws Exception { - assertTrue(config.size() > 0); - } - - @Test - public void testAddNoStrings() { - try { - config.add("aa", "b"); - fail(); - } - catch (IllegalArgumentException e) {} - } - - @Test - public void testAdd() { - // clear default values - config.update(new String[] {}); - - config.add("Mega favorite", new OpenersConfig.Opener("a@@@0@@@c")); - assertEquals("a", config.getOpener("Mega favorite").execString); - assertEquals(false, config.getOpener("Mega favorite").inTerminal); - assertEquals("c", config.getOpener("Mega favorite").workingDir.getName()); - assertEquals(1, config.size()); - } - - @Test - public void testOpenerDeserialize() { - OpenersConfig.Opener o = new OpenersConfig.Opener("uu@@uu@@@1@@@"); - assertEquals("uu@@uu", o.execString); - assertEquals(true, o.inTerminal); - assertEquals(null, o.workingDir); - - o = new OpenersConfig.Opener("c:\\program files\\mega app\\app.exe@@@0@@@c:\\windoze system"); - assertEquals("c:\\program files\\mega app\\app.exe", o.execString); - assertEquals(false, o.inTerminal); - assertEquals("c:\\windoze system", o.workingDir.toString()); - } - - @Test - public void testLoad() throws Exception { - preferences.put(PREFERENCE_NAME, "aa###aaa@@@1@@@###bb###bbb@@@1@@@"); - OpenersConfig config = new OpenersConfig(preferences); - - assertEquals("aaa", config.getOpener("aa").execString); - assertEquals("bbb", config.getOpener("bb").execString); - assertEquals(2, config.size()); - } - - @Test @SuppressWarnings("unchecked") - public void testOrder() throws Exception { - preferences.put(PREFERENCE_NAME, "aa###aaa@@@1@@@###bb###bbb@@@1@@@"); - OpenersConfig config = new OpenersConfig(preferences); - - Iterator namesIterator = config.iterateNames(); - assertEquals("aa", namesIterator.next()); - assertEquals("bb", namesIterator.next()); - assertFalse(namesIterator.hasNext()); - } - - @Test - public void testStore() throws Exception { - // clear default values - config.update(new String[] {}); - - config.add("x", new OpenersConfig.Opener("aa", true, null)); - config.add("x y z", new OpenersConfig.Opener("a a", true, new File("zzz z"))); - config.store(); - - assertEquals("x###aa@@@1@@@###x y z###a a@@@1@@@zzz z", preferences.get(PREFERENCE_NAME, "")); - } - - @Test @SuppressWarnings("unchecked") - public void testUpdate() { - config.add("x", new OpenersConfig.Opener("aa", true, null)); - config.add("y", new OpenersConfig.Opener("bb", false, null)); - config.add("z", new OpenersConfig.Opener("ccc", false, null)); - - config.update(new String[] {"x", "z"}); - - Iterator i = config.iterateNames(); - assertEquals("x", i.next()); - assertEquals("z", i.next()); - assertFalse(i.hasNext()); - } - -} diff --git a/ipscan-unittest/src/net/azib/ipscan/core/InetAddressUtilsTest.java b/ipscan-unittest/src/net/azib/ipscan/core/InetAddressUtilsTest.java deleted file mode 100755 index 2637d805..00000000 --- a/ipscan-unittest/src/net/azib/ipscan/core/InetAddressUtilsTest.java +++ /dev/null @@ -1,101 +0,0 @@ -package net.azib.ipscan.core; - -import static org.junit.Assert.*; - -import java.net.InetAddress; -import java.net.NetworkInterface; -import java.net.UnknownHostException; -import java.util.Enumeration; - -import org.junit.Test; - -public class InetAddressUtilsTest { - - @Test - public void testStartRangeByNetmask() throws UnknownHostException { - assertEquals("127.0.1.64", InetAddressUtils.startRangeByNetmask( - InetAddress.getByName("127.0.1.92"), - InetAddress.getByName("255.255.255.192")).getHostAddress()); - assertEquals("127.0.0.15", InetAddressUtils.startRangeByNetmask( - InetAddress.getByName("127.0.0.15"), - InetAddress.getByName("255.255.255.255")).getHostAddress()); - assertEquals("192.10.0.0", InetAddressUtils.startRangeByNetmask( - InetAddress.getByName("192.10.11.13"), - InetAddress.getByName("255.255.0.0")).getHostAddress()); - } - - @Test - public void testEndRangeByNetmask() throws UnknownHostException { - assertEquals("127.0.1.127", InetAddressUtils.endRangeByNetmask( - InetAddress.getByName("127.0.1.92"), - InetAddress.getByName("255.255.255.192")).getHostAddress()); - assertEquals("127.0.0.15", InetAddressUtils.endRangeByNetmask( - InetAddress.getByName("127.0.0.15"), - InetAddress.getByName("255.255.255.255")).getHostAddress()); - assertEquals("192.10.255.255", InetAddressUtils.endRangeByNetmask( - InetAddress.getByName("192.10.11.13"), - InetAddress.getByName("255.255.0.0")).getHostAddress()); - } - - @Test - public void testIncrement() throws UnknownHostException { - assertEquals("127.0.0.2", InetAddressUtils.increment(InetAddress.getByName("127.0.0.1")).getHostAddress()); - assertEquals("128.0.0.0", InetAddressUtils.increment(InetAddress.getByName("127.255.255.255")).getHostAddress()); - assertEquals("0.0.0.0", InetAddressUtils.increment(InetAddress.getByName("255.255.255.255")).getHostAddress()); - } - - @Test - public void testGreaterThan() throws UnknownHostException { - assertTrue(InetAddressUtils.greaterThan(InetAddress.getByName("127.0.0.1"), InetAddress.getByName("127.0.0.0"))); - assertTrue(InetAddressUtils.greaterThan(InetAddress.getByName("129.0.0.1"), InetAddress.getByName("128.0.0.0"))); - assertTrue(InetAddressUtils.greaterThan(InetAddress.getByName("255.0.0.0"), InetAddress.getByName("254.255.255.255"))); - assertFalse(InetAddressUtils.greaterThan(InetAddress.getByName("0.0.0.0"), InetAddress.getByName("255.255.255.255"))); - assertFalse(InetAddressUtils.greaterThan(InetAddress.getByName("0.0.0.0"), InetAddress.getByName("0.0.0.0"))); - assertFalse(InetAddressUtils.greaterThan(InetAddress.getByName("127.0.0.1"), InetAddress.getByName("127.0.5.0"))); - } - - @Test - public void testParseNetmask() throws UnknownHostException { - assertEquals("255.255.255.255", InetAddressUtils.parseNetmask("255.255.255.255").getHostAddress()); - assertEquals("255.255.255.255", InetAddressUtils.parseNetmask("255...255").getHostAddress()); - assertEquals("255.0.255.255", InetAddressUtils.parseNetmask("255.0..255").getHostAddress()); - assertEquals("255.255.255.192", InetAddressUtils.parseNetmask("255...192").getHostAddress()); - assertEquals("255.0.255.0", InetAddressUtils.parseNetmask("255.0..0").getHostAddress()); - assertEquals("0.0.0.0", InetAddressUtils.parseNetmask("0.0.0.0").getHostAddress()); - } - - @Test - public void testMaskPrototypeBytes() throws UnknownHostException { - byte[] bytes = InetAddress.getByName("32.23.34.254").getAddress(); - InetAddressUtils.maskPrototypeAddressBytes(bytes, InetAddress.getByName("255.0.0.255").getAddress(), InetAddress.getByName("29.1.2.255").getAddress()); - assertEquals("29.23.34.255", InetAddress.getByAddress(bytes).getHostAddress()); - - bytes = InetAddress.getByName("250.250.250.250").getAddress(); - InetAddressUtils.maskPrototypeAddressBytes(bytes, InetAddress.getByName("0.0.0.0").getAddress(), InetAddress.getByName("29.1.2.255").getAddress()); - assertEquals("250.250.250.250", InetAddress.getByAddress(bytes).getHostAddress()); - - bytes = InetAddress.getByName("250.250.250.250").getAddress(); - InetAddressUtils.maskPrototypeAddressBytes(bytes, InetAddress.getByName("255.255.255.255").getAddress(), InetAddress.getByName("29.128.127.73").getAddress()); - assertEquals("29.128.127.73", InetAddress.getByAddress(bytes).getHostAddress()); - } - - @Test - public void testIsLikelyBroadcast() throws UnknownHostException { - assertTrue(InetAddressUtils.isLikelyBroadcast(InetAddress.getByName("127.0.2.0"))); - assertTrue(InetAddressUtils.isLikelyBroadcast(InetAddress.getByName("127.6.32.255"))); - assertFalse(InetAddressUtils.isLikelyBroadcast(InetAddress.getByName("127.4.5.6"))); - } - - @Test - public void testGetAddressByName() throws Exception { - Enumeration ifaces = NetworkInterface.getNetworkInterfaces(); - ifaces.nextElement(); - if (ifaces.hasMoreElements()) { - // this test depends on the network configuraton of the system - // so we run it only if there are more than 1 network interface in the system (which is a loopback interface) - assertFalse(InetAddress.getByName(InetAddressUtils.getAddressByName(InetAddress.getLocalHost().getHostName())).isLoopbackAddress()); - assertFalse(InetAddress.getByName(InetAddressUtils.getAddressByName("localhost")).isLoopbackAddress()); - } - } - -} diff --git a/ipscan-unittest/src/net/azib/ipscan/core/IntegerWithUnitTest.java b/ipscan-unittest/src/net/azib/ipscan/core/IntegerWithUnitTest.java deleted file mode 100755 index 0452504d..00000000 --- a/ipscan-unittest/src/net/azib/ipscan/core/IntegerWithUnitTest.java +++ /dev/null @@ -1,57 +0,0 @@ -/** - * - */ -package net.azib.ipscan.core; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import net.azib.ipscan.config.Labels; -import net.azib.ipscan.core.values.IntegerWithUnit; - -import org.junit.Test; - -/** - * IntegerWithUnitTest - * - * @author anton - */ -public class IntegerWithUnitTest { - - @Test - public void testIntValue() throws Exception { - assertEquals(0, new IntegerWithUnit(0, "a").intValue()); - assertEquals(-1, new IntegerWithUnit(-1, "a").intValue()); - assertEquals(Integer.MAX_VALUE, new IntegerWithUnit(Integer.MAX_VALUE, "a").intValue()); - } - - @Test - public void testToString() throws Exception { - assertEquals("151" + Labels.getLabel("fetcher.value.ms"), new IntegerWithUnit(151, "fetcher.value.ms").toString()); - } - - @Test - public void testEquals() throws Exception { - assertTrue(new IntegerWithUnit(666, null).equals(new IntegerWithUnit(666, null))); - assertTrue(new IntegerWithUnit(42, "a").equals(new IntegerWithUnit(42, "b"))); - assertFalse(new IntegerWithUnit(0, null).equals(null)); - assertFalse(new IntegerWithUnit(42, "a").equals(new IntegerWithUnit(43, "a"))); - } - - @Test - public void testHashCode() throws Exception { - assertEquals(3, new IntegerWithUnit(3, null).hashCode()); - assertEquals(-31, new IntegerWithUnit(-31, null).hashCode()); - } - - @Test - public void testCompareTo() throws Exception { - assertTrue(Comparable.class.isAssignableFrom(IntegerWithUnit.class)); - assertEquals(0, new IntegerWithUnit(1, null).compareTo(new IntegerWithUnit(1, null))); - assertEquals(1, new IntegerWithUnit(123456789, null).compareTo(new IntegerWithUnit(123456, null))); - assertEquals(-1, new IntegerWithUnit(12, null).compareTo(new IntegerWithUnit(123456, null))); - assertEquals(1, new IntegerWithUnit(12, null).compareTo(null)); - IntegerWithUnit instance = new IntegerWithUnit(211082, null); - assertEquals(0, instance.compareTo(instance)); - } -} diff --git a/ipscan-unittest/src/net/azib/ipscan/core/PortIteratorTest.java b/ipscan-unittest/src/net/azib/ipscan/core/PortIteratorTest.java deleted file mode 100755 index b7110238..00000000 --- a/ipscan-unittest/src/net/azib/ipscan/core/PortIteratorTest.java +++ /dev/null @@ -1,48 +0,0 @@ -/** - * - */ -package net.azib.ipscan.core; - -import static org.junit.Assert.*; - -import org.junit.Test; - -/** - * PortIteratorTest - * - * @author anton - */ -public class PortIteratorTest { - - @Test - public void testBasic() { - assertEquals("1 2 3 5 7 ", iterateToString(new PortIterator("1,2,3,5,7"))); - assertEquals("27 1 65535 ", iterateToString(new PortIterator("27, 1;65535"))); - assertEquals("16 ", iterateToString(new PortIterator("16"))); - assertEquals("", iterateToString(new PortIterator(""))); - assertEquals("12 ", iterateToString(new PortIterator(" 12"))); - assertEquals("12 ", iterateToString(new PortIterator("12, "))); - // TODO assertEquals("", iterateToString(new PortIterator("65536"))); - } - - @Test - public void testRange() { - assertEquals("1 2 3 ", iterateToString(new PortIterator("1-3"))); - assertEquals("65530 65531 65532 65533 65534 65535 ", iterateToString(new PortIterator("65530-65535"))); - assertEquals("100 13 14 17 18 19 20 ", iterateToString(new PortIterator("100,13-14,17-20"))); - } - - @Test - public void testCopy() { - assertNotNull(new PortIterator("1").copy()); - } - - private static String iterateToString(PortIterator iterator) { - StringBuffer sb = new StringBuffer(64); - while (iterator.hasNext()) { - sb.append(iterator.next()).append(' '); - } - return sb.toString(); - } - -} diff --git a/ipscan-unittest/src/net/azib/ipscan/core/ScannerTest.java b/ipscan-unittest/src/net/azib/ipscan/core/ScannerTest.java deleted file mode 100755 index 929644d3..00000000 --- a/ipscan-unittest/src/net/azib/ipscan/core/ScannerTest.java +++ /dev/null @@ -1,148 +0,0 @@ -/** - * - */ -package net.azib.ipscan.core; - -import static org.easymock.EasyMock.createMock; -import static org.easymock.EasyMock.expect; -import static org.easymock.EasyMock.replay; -import static org.easymock.EasyMock.verify; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import java.net.InetAddress; -import java.net.UnknownHostException; -import java.util.Arrays; -import java.util.HashSet; -import java.util.Set; - -import net.azib.ipscan.config.Config; -import net.azib.ipscan.core.values.NotAvailableValue; -import net.azib.ipscan.core.values.NotScannedValue; -import net.azib.ipscan.fetchers.Fetcher; -import net.azib.ipscan.fetchers.FetcherRegistry; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -/** - * ScannerTest - * - * @author anton - */ -public class ScannerTest { - - private Set> initCalled = new HashSet>(); - private Set> cleanupCalled = new HashSet>(); - private Scanner scanner; - private FetcherRegistry fetcherRegistry; - - @Before - public void setUp() throws Exception { - Config.initialize(); - - fetcherRegistry = createMock(FetcherRegistry.class); - expect(fetcherRegistry.getSelectedFetchers()).andReturn( - Arrays.asList(new Fetcher[] {new FakeFetcher(), new AnotherFakeFetcher(), new AbortingFetcher(), new FailingFetcher()}) - ); - replay(fetcherRegistry); - - scanner = new Scanner(fetcherRegistry); - } - - @After - public void tearDown() { - verify(fetcherRegistry); - } - - @Test - public void testScan() throws Exception { - // scan the local host - ScanningResult scanningResult = new ScanningResult(InetAddress.getLocalHost(), 4); - scanner.scan(InetAddress.getLocalHost(), scanningResult); - - assertEquals(ScanningSubject.RESULT_TYPE_ALIVE, scanningResult.getType()); - assertEquals(InetAddress.getLocalHost(), scanningResult.getAddress()); - assertEquals(4, scanningResult.getValues().size()); - assertEquals("blah", scanningResult.getValues().get(0)); - assertEquals(NotAvailableValue.INSTANCE, scanningResult.getValues().get(1)); - assertEquals("666 ms", scanningResult.getValues().get(2)); - assertEquals(NotScannedValue.INSTANCE, scanningResult.getValues().get(3)); - } - - @Test - public void testInit() throws Exception { - scanner.init(); - - assertTrue(initCalled.contains(FakeFetcher.class)); - assertTrue(initCalled.contains(AnotherFakeFetcher.class)); - assertTrue(initCalled.contains(AbortingFetcher.class)); - } - - @Test - public void testCleanup() throws Exception { - scanner.cleanup(); - - assertTrue(cleanupCalled.contains(FakeFetcher.class)); - assertTrue(cleanupCalled.contains(AnotherFakeFetcher.class)); - assertTrue(cleanupCalled.contains(AbortingFetcher.class)); - } - - private class FakeFetcher implements Fetcher { - public String getLabel() { - return null; - } - - public Object scan(ScanningSubject subject) { - try { - // check that the IP is correct - assertEquals(InetAddress.getLocalHost(), subject.getIPAddress()); - - // set the result type to check after scanning - subject.setResultType(ScanningSubject.RESULT_TYPE_ALIVE); - - // try to set parameter here and read from another Fetcher - subject.setParameter("megaParam", new Long(211082)); - } - catch (UnknownHostException e) { - fail(); - } - return "blah"; - } - - public void init() { - initCalled.add(getClass()); - } - - public void cleanup() { - cleanupCalled.add(getClass()); - } - - } - - private class AnotherFakeFetcher extends FakeFetcher { - public Object scan(ScanningSubject subject) { - // the parameter was set by FakeFetcher - assertEquals(new Long(211082), subject.getParameter("megaParam")); - // try null as a return value - return null; - } - } - - private class AbortingFetcher extends FakeFetcher { - public Object scan(ScanningSubject subject) { - subject.abortScanning(); - return "666 ms"; - } - } - - private class FailingFetcher extends FakeFetcher { - public Object scan(ScanningSubject subject) { - fail("This fetcher should not be reached"); - return null; - } - } - -} diff --git a/ipscan-unittest/src/net/azib/ipscan/core/ScanningResultListTest.java b/ipscan-unittest/src/net/azib/ipscan/core/ScanningResultListTest.java deleted file mode 100755 index 422fc686..00000000 --- a/ipscan-unittest/src/net/azib/ipscan/core/ScanningResultListTest.java +++ /dev/null @@ -1,189 +0,0 @@ -/** - * - */ -package net.azib.ipscan.core; - -import static org.easymock.EasyMock.createMock; -import static org.easymock.EasyMock.expect; -import static org.easymock.EasyMock.replay; -import static org.easymock.EasyMock.verify; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import java.net.InetAddress; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Iterator; -import java.util.List; - -import net.azib.ipscan.config.Labels; -import net.azib.ipscan.core.values.NotScannedValue; -import net.azib.ipscan.fetchers.Fetcher; -import net.azib.ipscan.fetchers.FetcherRegistry; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -/** - * ScanningResultListTest - * - * @author anton - */ -public class ScanningResultListTest { - - private List fetchers = new ArrayList(Arrays.asList(new Fetcher[] {new DummyFetcher("fetcher.ip"), new DummyFetcher("fetcher.ping"), new DummyFetcher("fetcher.hostname"), new DummyFetcher("fetcher.ping.ttl")})); - - private FetcherRegistry fetcherRegistry; - private ScanningResultList scanningResults; - - @Before - public void setUp() throws Exception { - fetcherRegistry = createMock(FetcherRegistry.class); - expect(fetcherRegistry.getSelectedFetchers()) - .andReturn(fetchers).anyTimes(); - replay(fetcherRegistry); - - scanningResults = new ScanningResultList(fetcherRegistry); - } - - @After - public void tearDown() { - verify(fetcherRegistry); - } - - @Test - public void testAdd() throws Exception { - int index = scanningResults.add(InetAddress.getByName("10.0.0.5")); - assertEquals("10.0.0.5", scanningResults.getResult(index).getAddress().getHostAddress()); - assertEquals("10.0.0.5", scanningResults.getResult(index).getValues().get(0)); - } - - @Test - public void testIterator() throws Exception { - assertFalse(scanningResults.iterator().hasNext()); - scanningResults.add(InetAddress.getLocalHost()); - Iterator i = scanningResults.iterator(); - assertTrue(i.hasNext()); - assertTrue(i.next() instanceof ScanningResult); - assertFalse(i.hasNext()); - } - - @Test @SuppressWarnings("unchecked") - public void testClear() throws Exception { - fetcherRegistry.getSelectedFetchers().clear(); - fetcherRegistry.getSelectedFetchers().add(new DummyFetcher("hello")); - scanningResults.add(InetAddress.getLocalHost()); - scanningResults.clear(); - - assertFalse("Results must be empty", scanningResults.iterator().hasNext()); - assertEquals("Cached Fetchers must be re-initilized", 1, scanningResults.getFetchers().size()); - } - - @Test - public void testCachedFetchers() throws Exception { - fetcherRegistry.getSelectedFetchers().clear(); - assertEquals("Fetchers should be cached from the last scan", 4, scanningResults.getFetchers().size()); - } - - @Test - public void testRemove() throws Exception { - scanningResults.add(InetAddress.getByName("127.9.9.1")); - int i2 = scanningResults.add(InetAddress.getByName("127.9.9.2")); - int i3 = scanningResults.add(InetAddress.getByName("127.9.9.3")); - scanningResults.add(InetAddress.getByName("127.9.9.4")); - scanningResults.remove(new int[] {i2,i3}); - - Iterator i = scanningResults.iterator(); - assertTrue(i.hasNext()); - assertEquals(InetAddress.getByName("127.9.9.1"), ((ScanningResult)i.next()).getAddress()); - assertTrue(i.hasNext()); - assertEquals(InetAddress.getByName("127.9.9.4"), ((ScanningResult)i.next()).getAddress()); - assertFalse(i.hasNext()); - } - - @Test - public void testSort() throws Exception { - scanningResults.add(InetAddress.getByName("127.9.9.1")); - scanningResults.getResult(0).setValue(1, "x"); - scanningResults.add(InetAddress.getByName("127.9.9.2")); - scanningResults.getResult(1).setValue(1, "a"); - scanningResults.add(InetAddress.getByName("127.9.9.3")); - scanningResults.getResult(2).setValue(1, "z"); - scanningResults.add(InetAddress.getByName("127.9.9.4")); - scanningResults.getResult(3).setValue(1, "m"); - - scanningResults.sort(1); - - Iterator i = scanningResults.iterator(); - assertEquals(InetAddress.getByName("127.9.9.2"), ((ScanningResult)i.next()).getAddress()); - assertEquals(InetAddress.getByName("127.9.9.4"), ((ScanningResult)i.next()).getAddress()); - assertEquals(InetAddress.getByName("127.9.9.1"), ((ScanningResult)i.next()).getAddress()); - assertEquals(InetAddress.getByName("127.9.9.3"), ((ScanningResult)i.next()).getAddress()); - assertFalse(i.hasNext()); - } - - @Test @SuppressWarnings("unchecked") - public void testGetResultsAsString() throws Exception { - List fetchers = scanningResults.getFetchers(); - int index = scanningResults.add(InetAddress.getByName("172.28.43.55")); - ScanningResult result = scanningResults.getResult(index); - result.setValue(1, "123"); - result.setValue(2, "xxxxx"); - result.setValue(3, null); - - String s = scanningResults.getResultsAsString(index); - String ln = System.getProperty("line.separator"); - assertTrue(s.endsWith(ln)); - assertTrue(s.indexOf(Labels.getLabel(fetchers.get(0).getLabel()) + ":\t172.28.43.55" + ln) >= 0); - assertTrue(s.indexOf(Labels.getLabel(fetchers.get(1).getLabel()) + ":\t123" + ln) >= 0); - assertTrue(s.indexOf(Labels.getLabel(fetchers.get(2).getLabel()) + ":\txxxxx" + ln) >= 0); - assertTrue(s.indexOf(Labels.getLabel(fetchers.get(3).getLabel()) + ":\t" + ln) >= 0); - } - - @Test - public void testFindText() throws Exception { - scanningResults.add(InetAddress.getByName("127.9.9.1")); - scanningResults.getResult(0).setValue(1, NotScannedValue.INSTANCE); - scanningResults.add(InetAddress.getByName("127.9.9.2")); - scanningResults.getResult(1).setValue(1, new Long(123456789L)); - scanningResults.add(InetAddress.getByName("127.9.9.3")); - scanningResults.getResult(2).setValue(1, "zzzz"); - scanningResults.add(InetAddress.getByName("127.9.9.4")); - scanningResults.getResult(3).setValue(1, "mmmmm"); - scanningResults.add(InetAddress.getByName("127.9.9.5")); - scanningResults.getResult(4).setValue(1, null); - scanningResults.add(InetAddress.getByName("127.9.9.6")); - scanningResults.getResult(5).setValue(1, InetAddress.getByName("127.0.0.1")); - - assertEquals(-1, scanningResults.findText("sometext", 0)); - assertEquals(1, scanningResults.findText("345", 0)); - assertEquals(-1, scanningResults.findText("345", 2)); - assertEquals(3, scanningResults.findText("m", 2)); - assertEquals(5, scanningResults.findText("0.0.", 2)); - } - - private static class DummyFetcher implements Fetcher { - private String label; - - public DummyFetcher(String label) { - this.label = label; - } - - public String getLabel() { - return label; - } - - public Object scan(ScanningSubject subject) { - return null; - } - - public void cleanup() { - } - - public void init() { - } - } - -} diff --git a/ipscan-unittest/src/net/azib/ipscan/core/net/ICMPSharedPingerTest.java b/ipscan-unittest/src/net/azib/ipscan/core/net/ICMPSharedPingerTest.java deleted file mode 100755 index 25d6c6f9..00000000 --- a/ipscan-unittest/src/net/azib/ipscan/core/net/ICMPSharedPingerTest.java +++ /dev/null @@ -1,29 +0,0 @@ -/** - * - */ -package net.azib.ipscan.core.net; - -import static org.junit.Assert.assertTrue; - -import java.net.InetAddress; - -import org.junit.Ignore; -import org.junit.Test; - -/** - * SharedPingerTest - * - * @author anton - */ -public class ICMPSharedPingerTest { - - @Test @Ignore("this test works only under root") - public void testPing() throws Exception { - Pinger pinger = new ICMPSharedPinger(1000); - PingResult result = pinger.ping(InetAddress.getLocalHost(), 3); - assertTrue(result.getAverageTime() >= 0); - assertTrue(result.getAverageTime() < 50); - assertTrue(result.getTTL() >= 0); - } - -} diff --git a/ipscan-unittest/src/net/azib/ipscan/core/net/PingerRegistryImplTest.java b/ipscan-unittest/src/net/azib/ipscan/core/net/PingerRegistryImplTest.java deleted file mode 100755 index 344b5540..00000000 --- a/ipscan-unittest/src/net/azib/ipscan/core/net/PingerRegistryImplTest.java +++ /dev/null @@ -1,49 +0,0 @@ -/** - * - */ -package net.azib.ipscan.core.net; - -import static org.junit.Assert.*; -import net.azib.ipscan.config.Labels; - -import org.junit.Before; -import org.junit.Test; - -/** - * PingerRegistryImplTest - * - * @author Anton Keks - */ -public class PingerRegistryImplTest { - - @Before - public void setUp() { - System.setProperty("java.library.path", "../swt/lib"); - } - - @Test - public void testGetRegisteredNames() throws Exception { - String[] names = new PingerRegistryImpl().getRegisteredNames(); - assertNotNull(names); - for (int i = 0; i < names.length; i++) { - assertNotNull(Labels.getLabel(names[i])); - } - } - - @Test - public void testCreatePinger() throws Exception { - PingerRegistry registry = new PingerRegistryImpl(); - String[] names = registry.getRegisteredNames(); - for (int i = 0; i < names.length; i++) { - try { - Pinger pinger = registry.createPinger(names[i], 0); - pinger.close(); - } - catch (RuntimeException e) { - // ignore IOExceptions in case RawSockets cannot be initialized - // under current conditions - assertTrue(e.getMessage().startsWith("Unable to create pinger")); - } - } - } -} diff --git a/ipscan-unittest/src/net/azib/ipscan/core/values/NotAvailableValueTest.java b/ipscan-unittest/src/net/azib/ipscan/core/values/NotAvailableValueTest.java deleted file mode 100755 index f648e82c..00000000 --- a/ipscan-unittest/src/net/azib/ipscan/core/values/NotAvailableValueTest.java +++ /dev/null @@ -1,37 +0,0 @@ -/** - * - */ -package net.azib.ipscan.core.values; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import net.azib.ipscan.config.Config; - -import org.junit.Test; - -/** - * NotAvailableValueTest - * - * @author anton - */ -public class NotAvailableValueTest { - - @Test - public void testEquals() throws Exception { - assertEquals(NotAvailableValue.INSTANCE, NotAvailableValue.INSTANCE); - } - - @Test - public void testToString() throws Exception { - Config.initialize(); - assertEquals(Config.getGlobal().notAvailableText, NotAvailableValue.INSTANCE.toString()); - } - - @Test - public void testCompareTo() throws Exception { - assertTrue(Comparable.class.isAssignableFrom(NotAvailableValue.class)); - assertEquals(0, NotAvailableValue.INSTANCE.compareTo(NotAvailableValue.INSTANCE)); - assertEquals(-1, NotAvailableValue.INSTANCE.compareTo("Hello")); - assertEquals(1, NotAvailableValue.INSTANCE.compareTo(null)); - } -} diff --git a/ipscan-unittest/src/net/azib/ipscan/core/values/NotScannedValueTest.java b/ipscan-unittest/src/net/azib/ipscan/core/values/NotScannedValueTest.java deleted file mode 100755 index e64c562d..00000000 --- a/ipscan-unittest/src/net/azib/ipscan/core/values/NotScannedValueTest.java +++ /dev/null @@ -1,38 +0,0 @@ -/** - * - */ -package net.azib.ipscan.core.values; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import net.azib.ipscan.config.Config; - -import org.junit.Test; - -/** - * NotScannedValueTest - * - * @author anton - */ -public class NotScannedValueTest { - - @Test - public void testEquals() throws Exception { - assertEquals(NotScannedValue.INSTANCE, NotScannedValue.INSTANCE); - } - - @Test - public void testToString() throws Exception { - Config.initialize(); - assertEquals(Config.getGlobal().notScannedText, NotScannedValue.INSTANCE.toString()); - } - - @Test - public void testCompareTo() throws Exception { - assertTrue(Comparable.class.isAssignableFrom(NotScannedValue.class)); - assertEquals(0, NotScannedValue.INSTANCE.compareTo(NotScannedValue.INSTANCE)); - assertEquals(-1, NotScannedValue.INSTANCE.compareTo("Hello")); - assertEquals(1, NotScannedValue.INSTANCE.compareTo(null)); - } - -} diff --git a/ipscan-unittest/src/net/azib/ipscan/core/values/NumericListValueTest.java b/ipscan-unittest/src/net/azib/ipscan/core/values/NumericListValueTest.java deleted file mode 100755 index 260a06b2..00000000 --- a/ipscan-unittest/src/net/azib/ipscan/core/values/NumericListValueTest.java +++ /dev/null @@ -1,30 +0,0 @@ -/** - * - */ -package net.azib.ipscan.core.values; - -import static org.junit.Assert.assertEquals; - -import java.util.Arrays; -import java.util.Collections; -import java.util.TreeSet; - -import org.junit.Test; - - -/** - * @author Anton Keks - */ -public class NumericListValueTest { - - @Test - public void testToString() { - assertEquals("", new NumericListValue(Collections.EMPTY_LIST, true).toString()); - assertEquals("1", new NumericListValue(Arrays.asList(new Object[] {1}), true).toString()); - assertEquals("1-3", new NumericListValue(Arrays.asList(new Object[] {1, 2, 3}), true).toString()); - assertEquals("1-3", new NumericListValue(new TreeSet(Arrays.asList(new Integer[] {2, 3, 1})), true).toString()); - assertEquals("1,2,3", new NumericListValue(Arrays.asList(new Object[] {1, 2, 3}), false).toString()); - assertEquals("1,5-6,15", new NumericListValue(Arrays.asList(new Object[] {1, 5, 6, 15}), true).toString()); - assertEquals("103,85,89,1", new NumericListValue(Arrays.asList(new Object[] {103, 85, 89, 1}), true).toString()); - } -} diff --git a/ipscan-unittest/src/net/azib/ipscan/exporters/AbstractExporterTestCase.java b/ipscan-unittest/src/net/azib/ipscan/exporters/AbstractExporterTestCase.java deleted file mode 100755 index 0b08c123..00000000 --- a/ipscan-unittest/src/net/azib/ipscan/exporters/AbstractExporterTestCase.java +++ /dev/null @@ -1,145 +0,0 @@ -/** - * - */ -package net.azib.ipscan.exporters; - -import static org.junit.Assert.*; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.OutputStream; -import java.net.InetAddress; - -import net.azib.ipscan.config.Labels; -import junit.framework.ComparisonFailure; - -import org.junit.Before; -import org.junit.Test; - -/** - * TestCase for Exporters. - * It contains initialization and generic tests for any Exporter. - * - * @author anton - */ -public abstract class AbstractExporterTestCase { - - protected Exporter exporter; - protected ByteArrayOutputStream outputStream; - protected String outputContent; - - protected abstract Exporter createExporter(); - - @Before - public void setUp() throws Exception { - outputStream = new ByteArrayOutputStream(); - exporter = createExporter(); - } - - @Test - public void testLabel() { - assertNotNull(Labels.getLabel(exporter.getLabel())); - } - - @Test - public void testFilenameExtension() { - assertNotNull(exporter.getFilenameExtension()); - } - - @Test - public void testStreamFlushAndClose() throws IOException { - final boolean wasClosed[] = new boolean[] {false, false}; - Exporter exporter2 = createExporter(); - OutputStream mockOutputStream = new OutputStream() { - public void write(int b) throws IOException { - } - public void close() throws IOException { - wasClosed[0] = true; - } - public void flush() { - wasClosed[1] = true; - } - }; - exporter2.start(mockOutputStream, "feederstuff"); - // output something to ensure that the flush will be called - exporter2.setFetchers(new String[] {Labels.getLabel("fetcher.ip"), Labels.getLabel("fetcher.ports")}); - exporter2.nextAdressResults(new Object[] {"1", "2"}); - // this should invoke flush among other things - exporter2.end(); - // close: no - assertFalse(wasClosed[0]); - // flush: yes - assertTrue(wasClosed[1]); - } - - @Test - public void testBasic() throws Exception { - exporter.start(outputStream, "feederstuff"); - exporter.setFetchers(new String[] {"IP", "hello", "fetcher2"}); - exporter.nextAdressResults(new Object[] {InetAddress.getLocalHost().getHostAddress(), "world", new Integer(53)}); - exporter.nextAdressResults(new Object[] {InetAddress.getLocalHost().getHostAddress(), "buga", new Integer(-1)}); - exporter.end(); - assertContains(InetAddress.getLocalHost().getHostAddress()); - assertContains("hello"); - assertContains("fetcher2"); - assertContains("world"); - assertContains("53"); - assertContains("buga"); - assertContains("-1"); - } - - @Test - public void testFetchersWithoutAppend() throws IOException { - exporter.start(outputStream, "feederstuff"); - exporter.setFetchers(new String[] {"IP", "fetcher1", "mega long fetcher 2"}); - exporter.end(); - assertContains("IP"); - assertContains("fetcher1"); - assertContains("mega long fetcher 2"); - } - - @Test - public void testFetchersWithAppend() throws IOException { - exporter.setAppend(true); - exporter.start(outputStream, "feederstuff"); - exporter.setFetchers(new String[] {"IP", "fetcher1", "mega long fetcher 2"}); - exporter.end(); - assertNotContains("IP"); - assertNotContains("fetcher1"); - assertNotContains("mega long fetcher 2"); - } - - @Test - public void testClone() throws CloneNotSupportedException { - Exporter exporter2 = (Exporter) exporter.clone(); - assertNotSame(exporter, exporter2); - } - - @Test - public void testNextAddressResultsWithNulls() throws IOException { - exporter.start(outputStream, "feederstuff"); - exporter.setFetchers(new String[] {"IP", "fetcher1", "mega long fetcher 2"}); - exporter.nextAdressResults(new Object[] {InetAddress.getLocalHost(), null, null}); - exporter.end(); - } - - protected void assertContains(String string, boolean contains) throws IOException { - if (outputContent == null) { - outputStream.close(); - // TODO: encoding??? - outputContent = new String(outputStream.toByteArray()); - } - - if (!((outputContent.indexOf(string) >= 0) ^ (!contains))) { - throw new ComparisonFailure("Contains check failed", string, outputContent); - } - } - - protected void assertContains(String string) throws IOException { - assertContains(string, true); - } - - protected void assertNotContains(String string) throws IOException { - assertContains(string, false); - } -} diff --git a/ipscan-unittest/src/net/azib/ipscan/exporters/CSVExporterTest.java b/ipscan-unittest/src/net/azib/ipscan/exporters/CSVExporterTest.java deleted file mode 100755 index 5c28fd39..00000000 --- a/ipscan-unittest/src/net/azib/ipscan/exporters/CSVExporterTest.java +++ /dev/null @@ -1,52 +0,0 @@ -/** - * - */ -package net.azib.ipscan.exporters; - -import static org.junit.Assert.*; - -import java.io.IOException; -import java.net.InetAddress; - -import org.junit.Test; - -/** - * CSV Exporter Test - * - * @author anton - */ -public class CSVExporterTest extends AbstractExporterTestCase { - - protected Exporter createExporter() { - return new CSVExporter(); - } - - @Test - public void testCSVSafeString() { - assertEquals(".a.bb.c.d.", ((CSVExporter)exporter).csvSafeString(",a,bb,c,d,")); - assertEquals("", ((CSVExporter)exporter).csvSafeString("")); - assertEquals("uuuuhha;", ((CSVExporter)exporter).csvSafeString("uuuuhha;")); - assertEquals("", ((CSVExporter)exporter).csvSafeString(null)); - assertEquals("123", ((CSVExporter)exporter).csvSafeString(new Long(123))); - } - - @Test - public void testFetchersWithoutAppend() throws IOException { - exporter.start(outputStream, null); - exporter.setFetchers(new String[] {"fet1", "hello2", "Mega Fetcher", "oops, comma here"}); - exporter.end(); - assertContains("fet1"); - assertContains("Mega Fetcher"); - assertContains("oops. comma here"); - } - - @Test - public void testNextAddressResults() throws IOException { - exporter.start(outputStream, null); - exporter.setFetchers(new String[] {"fet1", "hello2"}); - exporter.nextAdressResults(new Object[] {InetAddress.getLocalHost(), "oops, comma"}); - exporter.end(); - assertContains("oops. comma"); - } - -} diff --git a/ipscan-unittest/src/net/azib/ipscan/exporters/ExportProcessorTest.java b/ipscan-unittest/src/net/azib/ipscan/exporters/ExportProcessorTest.java deleted file mode 100755 index f4487a47..00000000 --- a/ipscan-unittest/src/net/azib/ipscan/exporters/ExportProcessorTest.java +++ /dev/null @@ -1,112 +0,0 @@ -/** - * - */ -package net.azib.ipscan.exporters; - -import static org.easymock.EasyMock.createMock; -import static org.easymock.EasyMock.expect; -import static org.easymock.EasyMock.replay; -import static org.easymock.EasyMock.verify; -import static org.junit.Assert.assertTrue; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileReader; -import java.io.IOException; -import java.net.InetAddress; -import java.util.Collections; - -import net.azib.ipscan.config.Labels; -import net.azib.ipscan.core.ScanningResult; -import net.azib.ipscan.core.ScanningResultList; -import net.azib.ipscan.exporters.ExportProcessor.ScanningResultSelector; -import net.azib.ipscan.fetchers.FetcherRegistry; -import net.azib.ipscan.fetchers.IPFetcher; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -/** - * ExportProcessorTest - * - * @author anton - */ -public class ExportProcessorTest { - - private FetcherRegistry fetcherRegistry; - - @Before - public void setUp() { - fetcherRegistry = createMock(FetcherRegistry.class); - expect(fetcherRegistry.getSelectedFetchers()) - .andReturn(Collections.singletonList(new IPFetcher())).anyTimes(); - replay(fetcherRegistry); - } - - @After - public void tearDown() { - verify(fetcherRegistry); - } - - @Test - public void testProcess() throws Exception { - File file = File.createTempFile("exportTest", "txt"); - ExportProcessor exportProcessor = new ExportProcessor(new TXTExporter(), file.getAbsolutePath()); - - ScanningResultList scanningResultList = new ScanningResultList(fetcherRegistry); - scanningResultList.add(InetAddress.getByName("192.168.0.13")); - exportProcessor.process(scanningResultList, "megaFeeder", null); - - String content = readFileContent(file); - - assertTrue(content.indexOf("megaFeeder") > 0); - assertTrue(content.indexOf(Labels.getLabel(new IPFetcher().getLabel())) > 0); - assertTrue(content.indexOf("fooBar") < 0); - assertTrue(content.indexOf("192.168.0.13") > 0); - } - - /** - * @param file - * @throws FileNotFoundException - * @throws IOException - */ - private String readFileContent(File file) throws FileNotFoundException, IOException { - StringBuffer buffer = new StringBuffer(); - BufferedReader reader = new BufferedReader(new FileReader(file)); - String line; - while((line = reader.readLine()) != null) { - buffer.append(line); - } - reader.close(); - return buffer.toString(); - } - - @Test - public void testProcessWithSelector() throws Exception { - File file = File.createTempFile("exportTest", "txt"); - ExportProcessor exportProcessor = new ExportProcessor(new TXTExporter(), file.getAbsolutePath()); - - ScanningResultList scanningResultList = new ScanningResultList(fetcherRegistry); - - scanningResultList.add(InetAddress.getByName("192.168.13.66")); - scanningResultList.add(InetAddress.getByName("192.168.13.67")); - scanningResultList.add(InetAddress.getByName("192.168.13.76")); - - exportProcessor.process(scanningResultList, "feeder2", new ScanningResultSelector() { - public boolean isResultSelected(int index, ScanningResult result) { - // select only IP addresses ending with 6 - return ((String)result.getValues().get(0)).endsWith("6"); - } - }); - - String content = readFileContent(file); - - assertTrue(content.indexOf("feeder2") > 0); - assertTrue(content.indexOf("192.168.13.66") > 0); - assertTrue(content.indexOf("192.168.13.67") < 0); - assertTrue(content.indexOf("192.168.13.76") > 0); - } - -} diff --git a/ipscan-unittest/src/net/azib/ipscan/exporters/ExporterRegistryTest.java b/ipscan-unittest/src/net/azib/ipscan/exporters/ExporterRegistryTest.java deleted file mode 100755 index 6a5f69cc..00000000 --- a/ipscan-unittest/src/net/azib/ipscan/exporters/ExporterRegistryTest.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * - */ -package net.azib.ipscan.exporters; - -import static org.junit.Assert.*; - -import java.util.Iterator; - -import org.junit.Test; - -/** - * ExporterRegistryTest - * - * @author anton - */ -public class ExporterRegistryTest { - - private ExporterRegistry exporterRegistry = new ExporterRegistry(new Exporter[] {new TXTExporter(), new CSVExporter()}); - - @Test - public void testIterator() { - for (Iterator i = exporterRegistry.iterator(); i.hasNext(); ) { - Exporter exporter = (Exporter) i.next(); - assertNotNull(exporter); - assertNotNull(exporter.getFilenameExtension()); - } - } - - @Test - public void testCreate() { - Exporter exporter; - - exporter = exporterRegistry.createExporter("aa.abc." + new TXTExporter().getFilenameExtension()); - assertTrue(exporter instanceof TXTExporter); - - exporter = exporterRegistry.createExporter("/tmp/foo/megafile." + new TXTExporter().getFilenameExtension()); - assertTrue(exporter instanceof TXTExporter); - } - - @Test - public void testCreateFailed() { - try { - exporterRegistry.createExporter("noextension"); - fail(); - } - catch (ExporterException e) { - assertEquals("exporter.unknown", e.getMessage()); - } - - try { - exporterRegistry.createExporter("unknown.extension"); - fail(); - } - catch (ExporterException e) { - assertEquals("exporter.unknown", e.getMessage()); - } - } - -} diff --git a/ipscan-unittest/src/net/azib/ipscan/exporters/IPListExporterTest.java b/ipscan-unittest/src/net/azib/ipscan/exporters/IPListExporterTest.java deleted file mode 100755 index 7f8b94b7..00000000 --- a/ipscan-unittest/src/net/azib/ipscan/exporters/IPListExporterTest.java +++ /dev/null @@ -1,87 +0,0 @@ -/** - * - */ -package net.azib.ipscan.exporters; - -import static org.junit.Assert.*; - -import java.io.IOException; -import java.net.InetAddress; -import java.util.Locale; - -import org.junit.Before; -import org.junit.Test; - -import net.azib.ipscan.config.Labels; - -/** - * IP List Exporter Test - * - * @author anton - */ -public class IPListExporterTest extends AbstractExporterTestCase { - - @Before - public void setUp() throws Exception { - Labels.initialize(Locale.ENGLISH); - super.setUp(); - } - - protected Exporter createExporter() { - return new IPListExporter(); - } - - @Test - public void testBasic() throws IOException { - Labels labels = Labels.getInstance(); - - exporter.start(outputStream, "feederstuff"); - exporter.setFetchers(new String[] {"fetcher1", labels.get("fetcher.ip"), "mega long fetcher 2", labels.get("fetcher.ports")}); - exporter.nextAdressResults(new Object[] {"", "123", "", "1,23; 4-6 78"}); - exporter.end(); - - assertContains("123:1"); - assertContains("123:23"); - assertContains("123:4"); - assertContains("123:5"); - assertContains("123:6"); - assertContains("123:78"); - } - - @Test - public void testFetchersWithAppend() throws IOException { - // default implementation doesn't work - } - - @Test - public void testFetchersWithoutAppend() throws IOException { - // default implementation doesn't work - } - - @Test - public void testNextAddressResultsWithNulls() throws IOException { - Labels labels = Labels.getInstance(); - - exporter.start(outputStream, "feederstuff"); - exporter.setFetchers(new String[] {labels.get("fetcher.ip"), "fetcher1", labels.get("fetcher.ports")}); - exporter.nextAdressResults(new Object[] {InetAddress.getLocalHost(), null, null}); - exporter.end(); - } - - @Test - public void testFindFetcherByLabel() { - Labels labels = Labels.getInstance(); - - assertEquals(0, IPListExporter.findFetcherByLabel("fetcher.ip", new String[] {labels.get("fetcher.ip")})); - assertEquals(3, IPListExporter.findFetcherByLabel("fetcher.ip", new String[] {"a", "b", "c", labels.get("fetcher.ip")})); - assertEquals(1, IPListExporter.findFetcherByLabel("fetcher.ports", new String[] {labels.get("fetcher.ports") + "x", labels.get("fetcher.ports"), "mmmm"})); - - try { - IPListExporter.findFetcherByLabel("fetcher.ip", new String[] {"1", "2"}); - fail(); - } - catch (ExporterException e) { - assertEquals("fetcher.notFound", e.getMessage()); - } - } -} diff --git a/ipscan-unittest/src/net/azib/ipscan/exporters/TXTExporterTest.java b/ipscan-unittest/src/net/azib/ipscan/exporters/TXTExporterTest.java deleted file mode 100755 index ab0c3b7a..00000000 --- a/ipscan-unittest/src/net/azib/ipscan/exporters/TXTExporterTest.java +++ /dev/null @@ -1,70 +0,0 @@ -/** - * - */ -package net.azib.ipscan.exporters; - -import static org.junit.Assert.*; - -import java.io.IOException; - -import org.junit.Test; - -import net.azib.ipscan.config.Version; - -/** - * TXT Exporter Test - * - * @author anton - */ -public class TXTExporterTest extends AbstractExporterTestCase { - - protected Exporter createExporter() { - return new TXTExporter(); - } - - @Test - public void testPad() { - assertEquals("a ", ((TXTExporter)exporter).pad("a", 1)); - assertEquals(" ", ((TXTExporter)exporter).pad("", 0)); - assertEquals("abc ", ((TXTExporter)exporter).pad("abc", 20)); - assertEquals(" ", ((TXTExporter)exporter).pad(null, 5)); - assertEquals("5 ", ((TXTExporter)exporter).pad(new Integer(5), 5)); - } - - @Test - public void testHeaderWithoutAppend() throws IOException { - exporter.start(outputStream, "feederstuff"); - exporter.end(); - assertContains(Version.FULL_NAME); - assertContains(Version.WEBSITE); - } - - @Test - public void testHeaderWithAppend() throws IOException { - exporter.setAppend(true); - exporter.start(outputStream, "feederstuff"); - exporter.end(); - assertNotContains(Version.FULL_NAME); - assertNotContains(Version.WEBSITE); - } - - @Test - public void testFetchersWithAppend() throws IOException { - super.testFetchersWithAppend(); - assertTrue(((TXTExporter)exporter).padLengths != null); - } - - @Test - public void testFetchersWithoutAppend() throws IOException { - super.testFetchersWithoutAppend(); - assertTrue(((TXTExporter)exporter).padLengths != null); - } - - @Test - public void testFeederInfo() throws IOException { - exporter.start(outputStream, "192.168.1.1 - 192.168.3.255"); - exporter.end(); - assertContains("192.168.1.1 - 192.168.3.255"); - } - -} diff --git a/ipscan-unittest/src/net/azib/ipscan/exporters/XMLExporterTest.java b/ipscan-unittest/src/net/azib/ipscan/exporters/XMLExporterTest.java deleted file mode 100755 index 13e51ada..00000000 --- a/ipscan-unittest/src/net/azib/ipscan/exporters/XMLExporterTest.java +++ /dev/null @@ -1,98 +0,0 @@ -/** - * - */ -package net.azib.ipscan.exporters; - -import static org.junit.Assert.*; - -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.net.InetAddress; -import java.util.Locale; - -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; - -import org.junit.Before; -import org.junit.Test; - -import net.azib.ipscan.config.Labels; -import net.azib.ipscan.config.Version; - -/** - * XML Exporter Test - * - * @author anton - */ -public class XMLExporterTest extends AbstractExporterTestCase { - - @Before - public void setUp() throws Exception { - Labels.initialize(Locale.ENGLISH); - super.setUp(); - } - - protected Exporter createExporter() { - return new XMLExporter(); - } - - @Test - public void testHeaderWithoutAppend() throws IOException { - exporter.start(outputStream, "feederstuff"); - exporter.end(); - assertContains(Version.FULL_NAME); - assertContains(Version.WEBSITE); - } - - @Test - public void testFetchersWithoutAppend() throws IOException { - exporter.start(outputStream, "feederstuff"); - exporter.setFetchers(new String[] {"fetcher1", Labels.getLabel("fetcher.ip"), "mega long fetcher 2"}); - exporter.nextAdressResults(new Object[] {"", "123", ""}); - exporter.end(); - assertContains("IP"); - assertContains("address=\"123\""); - assertContains("fetcher1"); - assertContains("mega long fetcher 2"); - } - - @Test - public void testFetchersWithAppend() { - try { - exporter.setAppend(true); - fail(); - } - catch (ExporterException e) { - assertEquals("xml.noAppend", e.getMessage()); - } - } - - @Test - public void testFeederInfoWithName() throws IOException { - exporter.start(outputStream, "Blah: 192.168.1.1 - 192.168.3.255"); - exporter.end(); - assertContains("name=\"Blah\""); - assertContains("192.168.1.1 - 192.168.3.255"); - } - - @Test - public void testFeederInfoNoName() throws IOException { - exporter.start(outputStream, "Booga 192.168.1.1/123"); - exporter.end(); - assertContains("Booga 192.168.1.1/123"); - } - - @Test - public void testValidXML() throws Exception { - exporter.start(outputStream, ">a", new Integer(-1)}); - exporter.end(); - assertContains("66.87.99.128\n000.87.99.1290000.1.1.1", 2); - } - - @Test - public void testGetPercentageComplete() throws Exception { - StringReader reader = new StringReader("1.2.3.4, 2.3.4.5, mega cool 0.0.0.0"); - FileFeeder fileFeeder = new FileFeeder(); - fileFeeder.initialize(reader); - assertEquals(0, fileFeeder.getPercentageComplete()); - fileFeeder.next(); - assertEquals(33, fileFeeder.getPercentageComplete()); - fileFeeder.next(); - assertEquals(67, fileFeeder.getPercentageComplete()); - fileFeeder.next(); - assertEquals(100, fileFeeder.getPercentageComplete()); - - reader = new StringReader("255.255.255.255"); - fileFeeder.initialize(reader); - assertEquals(0, fileFeeder.getPercentageComplete()); - fileFeeder.next(); - assertEquals(100, fileFeeder.getPercentageComplete()); - } - - @Test - public void testGetInfo() { - FileFeeder fileFeeder = new FileFeeder(); - StringReader reader = new StringReader("255.255.255.255, 2.3.4.5, mega cool 0.0.0.0"); - fileFeeder.initialize(reader); - assertEquals("3", fileFeeder.getInfo()); - } - - private void assertAddressCount(String s, int addressCount) { - StringReader reader = new StringReader(s); - FileFeeder feeder = new FileFeeder(); - feeder.initialize(reader); - int numAddresses = 0; - while (feeder.hasNext()) { - feeder.next(); - numAddresses++; - } - assertEquals(addressCount, numAddresses); - } - -} diff --git a/ipscan-unittest/src/net/azib/ipscan/feeders/RandomFeederTest.java b/ipscan-unittest/src/net/azib/ipscan/feeders/RandomFeederTest.java deleted file mode 100755 index 07f4c7e2..00000000 --- a/ipscan-unittest/src/net/azib/ipscan/feeders/RandomFeederTest.java +++ /dev/null @@ -1,144 +0,0 @@ -package net.azib.ipscan.feeders; - -import static net.azib.ipscan.feeders.FeederTestUtils.*; -import static org.junit.Assert.*; - -import org.junit.Test; - -/** - * Test of RandomFeeder - * - * @author anton - */ -public class RandomFeederTest { - - @Test - public void testHappyPath() throws FeederException { - RandomFeeder randomFeeder = new RandomFeeder(); - assertEquals(3, randomFeeder.initialize(new String[] {"255.255.255.255", "255...0", "2"})); - assertTrue(randomFeeder.hasNext()); - assertTrue(randomFeeder.next().getHostAddress().startsWith("255.255.255")); - assertTrue(randomFeeder.hasNext()); - assertTrue(randomFeeder.next().getHostAddress().startsWith("255.255.255")); - assertFalse(randomFeeder.hasNext()); - } - - @Test - public void testInvalidCount() { - try { - new RandomFeeder().initialize(new String[] {"1.1.1.1", "2.2.2.2", "abc"}); - fail(); - } - catch (FeederException e) { - assertFeederException("random.invalidCount", e); - } - try { - new RandomFeeder().initialize("1.1.1.1", "1.1.1.1", 0); - fail(); - } - catch (FeederException e) { - assertFeederException("random.invalidCount", e); - } - } - - @Test - public void testMalformedIP() { - try { - new RandomFeeder().initialize("abc", "10.11.12.10", 1); - fail(); - } - catch (FeederException e) { - assertFeederException("malformedIP", e); - } - } - - @Test - public void testInvalidNetmask() { - try { - new RandomFeeder().initialize("1.1.1.1", "invalid", 1); - fail(); - } - catch (FeederException e) { - assertFeederException("invalidNetmask", e); - } - } - - @Test - public void testFullMask() { - RandomFeeder randomFeeder = null; - randomFeeder = new RandomFeeder(); - randomFeeder.initialize("1.2.3.45", "255.255.255.255", 1); - assertTrue(randomFeeder.hasNext()); - assertEquals("1.2.3.45", randomFeeder.next().getHostAddress()); - assertFalse(randomFeeder.hasNext()); - } - - @Test - public void testEmptyMask() { - RandomFeeder randomFeeder = null; - randomFeeder = new RandomFeeder(); - randomFeeder.initialize("1.2.3.45", "0.0.0.0", 1); - assertTrue(randomFeeder.hasNext()); - assertFalse("1.2.3.45".equals(randomFeeder.next().getHostAddress())); - assertFalse(randomFeeder.hasNext()); - } - - @Test - public void testMaskStartEnd() { - RandomFeeder randomFeeder = null; - randomFeeder = new RandomFeeder(); - randomFeeder.initialize("1.2.3.45", "255.0.0.255", 1); - assertTrue(randomFeeder.hasNext()); - String address = randomFeeder.next().getHostAddress(); - assertTrue(address.startsWith("1.")); - assertTrue(address.endsWith(".45")); - assertFalse(randomFeeder.hasNext()); - } - - @Test - public void testDifferent() { - RandomFeeder randomFeeder = null; - String address = null; - - randomFeeder = new RandomFeeder(); - randomFeeder.initialize("1.2.3.45", "255.0.255.0", 2); - assertTrue(randomFeeder.hasNext()); - address = randomFeeder.next().getHostAddress(); - assertFalse("1.2.3.45".equals(address)); - assertTrue(randomFeeder.hasNext()); - assertFalse(address.equals(randomFeeder.next().getHostAddress())); - assertFalse(randomFeeder.hasNext()); - - randomFeeder.initialize("1.2.3.45", "255.0.127.0", 1); - assertTrue(randomFeeder.hasNext()); - assertFalse(address.equals(randomFeeder.next().getHostAddress())); - assertFalse(randomFeeder.hasNext()); - } - - @Test - public void testGetPercentageComplete() throws Exception { - RandomFeeder randomFeeder = new RandomFeeder(); - randomFeeder.initialize("100.11.12.13", "100.11.12.15", 3); - assertEquals(0, randomFeeder.getPercentageComplete()); - randomFeeder.next(); - assertEquals(33, randomFeeder.getPercentageComplete()); - randomFeeder.next(); - assertEquals(67, randomFeeder.getPercentageComplete()); - randomFeeder.next(); - assertEquals(100, randomFeeder.getPercentageComplete()); - - randomFeeder.initialize("255.255.255.255", "255.255.255.255", 1); - assertEquals(0, randomFeeder.getPercentageComplete()); - randomFeeder.next(); - assertEquals(100, randomFeeder.getPercentageComplete()); - } - - @Test - public void testGetInfo() { - RandomFeeder randomFeeder = new RandomFeeder(); - randomFeeder.initialize("100.11.12.13", "100.11.12.15", 3); - assertEquals("100.11.12.13 / 100.11.12.15: 3", randomFeeder.getInfo()); - randomFeeder.initialize("0.0.0.0", "255.255.255.255", 129876); - assertEquals("0.0.0.0 / 255.255.255.255: 129876", randomFeeder.getInfo()); - } -} diff --git a/ipscan-unittest/src/net/azib/ipscan/feeders/RangeFeederTest.java b/ipscan-unittest/src/net/azib/ipscan/feeders/RangeFeederTest.java deleted file mode 100755 index 1084f29c..00000000 --- a/ipscan-unittest/src/net/azib/ipscan/feeders/RangeFeederTest.java +++ /dev/null @@ -1,99 +0,0 @@ -package net.azib.ipscan.feeders; - -import static net.azib.ipscan.feeders.FeederTestUtils.*; -import static org.junit.Assert.*; - -import org.junit.Test; - -/** - * Test of RangeFeeder - * - * @author anton - */ -public class RangeFeederTest { - - @Test - public void testHappyPath() throws FeederException { - RangeFeeder rangeFeeder = new RangeFeeder(); - assertEquals(2, rangeFeeder.initialize(new String[] {"10.11.12.13", "10.11.12.15"})); - assertTrue(rangeFeeder.hasNext()); - assertEquals("10.11.12.13", rangeFeeder.next().getHostAddress()); - assertTrue(rangeFeeder.hasNext()); - assertEquals("10.11.12.14", rangeFeeder.next().getHostAddress()); - assertTrue(rangeFeeder.hasNext()); - assertEquals("10.11.12.15", rangeFeeder.next().getHostAddress()); - assertFalse(rangeFeeder.hasNext()); - } - - @Test - public void testInvalidRange() { - try { - new RangeFeeder().initialize("10.11.12.13", "10.11.12.10"); - fail(); - } - catch (FeederException e) { - assertFeederException("range.greaterThan", e); - } - } - - @Test - public void testMalformedIP() { - try { - new RangeFeeder().initialize("10.11.12.abc", "10.11.12.10"); - fail(); - } - catch (FeederException e) { - assertFeederException("malformedIP", e); - } - try { - new RangeFeeder().initialize("10.11.12.1", "ziga"); - fail(); - } - catch (FeederException e) { - assertFeederException("malformedIP", e); - } - } - - @Test - public void testExtremeValues() { - RangeFeeder rangeFeeder = null; - - rangeFeeder = new RangeFeeder(); - rangeFeeder.initialize("0.0.0.0", "0.0.0.0"); - assertTrue(rangeFeeder.hasNext()); - assertEquals("0.0.0.0", rangeFeeder.next().getHostAddress()); - assertFalse(rangeFeeder.hasNext()); - - rangeFeeder.initialize("255.255.255.255", "255.255.255.255"); - assertTrue(rangeFeeder.hasNext()); - assertEquals("255.255.255.255", rangeFeeder.next().getHostAddress()); - assertFalse(rangeFeeder.hasNext()); - } - - @Test - public void testGetPercentageComplete() throws Exception { - RangeFeeder rangeFeeder = new RangeFeeder(); - rangeFeeder.initialize("100.11.12.13", "100.11.12.15"); - assertEquals(0, rangeFeeder.getPercentageComplete()); - rangeFeeder.next(); - assertEquals(33, rangeFeeder.getPercentageComplete()); - rangeFeeder.next(); - assertEquals(67, rangeFeeder.getPercentageComplete()); - rangeFeeder.next(); - assertEquals(100, rangeFeeder.getPercentageComplete()); - - rangeFeeder.initialize("255.255.255.255", "255.255.255.255"); - assertEquals(0, rangeFeeder.getPercentageComplete()); - rangeFeeder.next(); - assertEquals(100, rangeFeeder.getPercentageComplete()); - } - - @Test - public void testGetInfo() { - RangeFeeder rangeFeeder = new RangeFeeder(); - rangeFeeder.initialize("100.11.12.13", "100.11.12.13"); - assertEquals("100.11.12.13 - 100.11.12.13", rangeFeeder.getInfo()); - rangeFeeder.initialize("0.0.0.0", "255.255.255.255"); - assertEquals("0.0.0.0 - 255.255.255.255", rangeFeeder.getInfo()); - } -} diff --git a/ipscan-unittest/src/net/azib/ipscan/fetchers/AbstractFetcherTestCase.java b/ipscan-unittest/src/net/azib/ipscan/fetchers/AbstractFetcherTestCase.java deleted file mode 100755 index 6ff43565..00000000 --- a/ipscan-unittest/src/net/azib/ipscan/fetchers/AbstractFetcherTestCase.java +++ /dev/null @@ -1,38 +0,0 @@ -/** - * - */ -package net.azib.ipscan.fetchers; - -import static org.junit.Assert.*; -import net.azib.ipscan.config.Config; -import net.azib.ipscan.config.Labels; - -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -/** - * TestCase for Fetchers. - * It contains initialization and generic tests for any Fetcher. - * - * @author anton - */ -public abstract class AbstractFetcherTestCase { - - Fetcher fetcher; - - @BeforeClass - public static void globalSetUp() { - // some fetchers are Configurable and therefore need an initialized Config - Config.initialize(); - } - - @Before - public abstract void setUp() throws Exception; - - @Test - public void testLabel() { - assertNotNull(Labels.getLabel(fetcher.getLabel())); - } - -} diff --git a/ipscan-unittest/src/net/azib/ipscan/fetchers/FetcherRegistryImplTest.java b/ipscan-unittest/src/net/azib/ipscan/fetchers/FetcherRegistryImplTest.java deleted file mode 100755 index fccc99a2..00000000 --- a/ipscan-unittest/src/net/azib/ipscan/fetchers/FetcherRegistryImplTest.java +++ /dev/null @@ -1,107 +0,0 @@ -/** - * - */ -package net.azib.ipscan.fetchers; - -import static org.junit.Assert.*; - -import java.util.Iterator; -import java.util.prefs.Preferences; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -/** - * @author Anton Keks - */ -public class FetcherRegistryImplTest { - - private Preferences preferences; - - private Fetcher ipFetcher; - private HostnameFetcher hostnameFetcher; - private CommentFetcher commentFetcher; - private FetcherRegistry fetcherRegistry; - - @Before - public void setUp() throws Exception { - preferences = Preferences.userRoot().node("ipscan-test"); - preferences.clear(); - - ipFetcher = new IPFetcher(); - hostnameFetcher = new HostnameFetcher(); - commentFetcher = new CommentFetcher(); - fetcherRegistry = new FetcherRegistryImpl(new Fetcher[] {ipFetcher, hostnameFetcher, commentFetcher}, preferences); - } - - @After - public void tearDown() throws Exception { - preferences.removeNode(); - } - - @Test - public void testCreate() throws Exception { - assertEquals(3, fetcherRegistry.getRegisteredFetchers().size()); - assertEquals(3, fetcherRegistry.getSelectedFetchers().size()); - } - - @Test(expected=UnsupportedOperationException.class) - public void testModifyRegisteredFetchers() throws Exception { - fetcherRegistry.getRegisteredFetchers().clear(); - } - - @Test - public void testGetSelectedFetcherIndex() throws Exception { - assertEquals(0, fetcherRegistry.getSelectedFetcherIndex(ipFetcher.getLabel())); - assertEquals(1, fetcherRegistry.getSelectedFetcherIndex(hostnameFetcher.getLabel())); - assertEquals(2, fetcherRegistry.getSelectedFetcherIndex(commentFetcher.getLabel())); - assertEquals(-1, fetcherRegistry.getSelectedFetcherIndex("blah-blah")); - } - - @Test - public void testLoadPreferences() throws Exception { - preferences.remove(FetcherRegistryImpl.PREFERENCE_SELECTED_FETCHERS); - fetcherRegistry = new FetcherRegistryImpl(new Fetcher[] {ipFetcher, hostnameFetcher, commentFetcher}, preferences); - assertEquals(3, fetcherRegistry.getSelectedFetchers().size()); - - preferences.put(FetcherRegistryImpl.PREFERENCE_SELECTED_FETCHERS, hostnameFetcher.getLabel() + "###" + commentFetcher.getLabel()); - fetcherRegistry = new FetcherRegistryImpl(new Fetcher[] {ipFetcher, hostnameFetcher, commentFetcher}, preferences); - assertEquals(2, fetcherRegistry.getSelectedFetchers().size()); - Iterator iterator = fetcherRegistry.getSelectedFetchers().iterator(); - assertSame(hostnameFetcher, iterator.next()); - assertSame(commentFetcher, iterator.next()); - } - - @Test - public void testUpdateSelectedFetchers() throws Exception { - // retain only one selected fetcher - fetcherRegistry.updateSelectedFetchers(new String[] {ipFetcher.getLabel()}); - assertEquals(1, fetcherRegistry.getSelectedFetchers().size()); - Iterator iterator = fetcherRegistry.getSelectedFetchers().iterator(); - assertEquals(ipFetcher.getLabel(), ((Fetcher)iterator.next()).getLabel()); - assertEquals(ipFetcher.getLabel(), preferences.get(FetcherRegistryImpl.PREFERENCE_SELECTED_FETCHERS, null)); - - // now return a fetcher back - fetcherRegistry.updateSelectedFetchers(new String[] {commentFetcher.getLabel(), ipFetcher.getLabel()}); - assertEquals(2, fetcherRegistry.getSelectedFetchers().size()); - iterator = fetcherRegistry.getSelectedFetchers().iterator(); - assertEquals(commentFetcher.getLabel(), ((Fetcher)iterator.next()).getLabel()); - assertEquals(ipFetcher.getLabel(), ((Fetcher)iterator.next()).getLabel()); - assertEquals(commentFetcher.getLabel() + "###" + ipFetcher.getLabel(), preferences.get(FetcherRegistryImpl.PREFERENCE_SELECTED_FETCHERS, null)); - } - - @Test - public void testListener() throws Exception { - final boolean listenerWasCalled[] = {false}; - fetcherRegistry.addListener(new FetcherRegistryUpdateListener() { - public void handleUpdateOfSelectedFetchers(FetcherRegistry fetcherRegistry) { - assertSame(FetcherRegistryImplTest.this.fetcherRegistry, fetcherRegistry); - assertEquals(0, fetcherRegistry.getSelectedFetchers().size()); - listenerWasCalled[0] = true; - } - }); - fetcherRegistry.updateSelectedFetchers(new String[] {}); - assertTrue(listenerWasCalled[0]); - } -} diff --git a/ipscan-unittest/src/net/azib/ipscan/fetchers/HostnameFetcherTest.java b/ipscan-unittest/src/net/azib/ipscan/fetchers/HostnameFetcherTest.java deleted file mode 100755 index 20241e29..00000000 --- a/ipscan-unittest/src/net/azib/ipscan/fetchers/HostnameFetcherTest.java +++ /dev/null @@ -1,39 +0,0 @@ -/** - * - */ -package net.azib.ipscan.fetchers; - -import static org.junit.Assert.*; - -import java.net.InetAddress; -import java.net.UnknownHostException; - -import org.junit.Before; -import org.junit.Test; - -import net.azib.ipscan.core.ScanningSubject; - -/** - * HostnameFetcherTest - * - * @author anton - */ -public class HostnameFetcherTest extends AbstractFetcherTestCase { - - @Before - public void setUp() throws Exception { - fetcher = new HostnameFetcher(); - } - - @Test - public void testScan() throws UnknownHostException { - // Some of these tests are run inside of if's to prevent their failing on certain network configurations - if (!InetAddress.getLocalHost().getCanonicalHostName().equals(InetAddress.getLocalHost().getHostAddress())) - assertEquals(InetAddress.getLocalHost().getCanonicalHostName(), fetcher.scan(new ScanningSubject(InetAddress.getLocalHost()))); - InetAddress wwweeAddress = InetAddress.getByName("194.204.33.30"); - if (!wwweeAddress.equals("194.204.33.30")) - assertEquals(wwweeAddress.getCanonicalHostName(), fetcher.scan(new ScanningSubject(wwweeAddress))); - assertNull(fetcher.scan(new ScanningSubject(InetAddress.getByName("255.255.255.255")))); - assertNull(fetcher.scan(new ScanningSubject(InetAddress.getByName("172.13.66.254")))); - } -} diff --git a/ipscan-unittest/src/net/azib/ipscan/fetchers/IPFetcherTest.java b/ipscan-unittest/src/net/azib/ipscan/fetchers/IPFetcherTest.java deleted file mode 100755 index 50a179b4..00000000 --- a/ipscan-unittest/src/net/azib/ipscan/fetchers/IPFetcherTest.java +++ /dev/null @@ -1,34 +0,0 @@ -/** - * - */ -package net.azib.ipscan.fetchers; - -import static org.junit.Assert.*; - -import java.net.InetAddress; -import java.net.UnknownHostException; - -import org.junit.Before; -import org.junit.Test; - -import net.azib.ipscan.core.ScanningSubject; - -/** - * IPFetcherTest - * - * @author anton - */ -public class IPFetcherTest extends AbstractFetcherTestCase { - - @Before - public void setUp() throws Exception { - fetcher = new IPFetcher(); - } - - @Test - public void testScan() throws UnknownHostException { - assertEquals(InetAddress.getLocalHost().getHostAddress(), fetcher.scan(new ScanningSubject(InetAddress.getLocalHost()))); - assertEquals("255.255.255.255", fetcher.scan(new ScanningSubject(InetAddress.getByName("255.255.255.255")))); - } - -} diff --git a/ipscan-unittest/src/net/azib/ipscan/fetchers/PingFetcherTest.java b/ipscan-unittest/src/net/azib/ipscan/fetchers/PingFetcherTest.java deleted file mode 100755 index b2ac5525..00000000 --- a/ipscan-unittest/src/net/azib/ipscan/fetchers/PingFetcherTest.java +++ /dev/null @@ -1,22 +0,0 @@ -/** - * - */ -package net.azib.ipscan.fetchers; - -import net.azib.ipscan.config.Config; - -import org.junit.Before; - -/** - * PingFetcherTest - * - * @author anton - */ -public class PingFetcherTest extends AbstractFetcherTestCase { - - @Before - public void setUp() throws Exception { - fetcher = new PingFetcher(null, Config.getGlobal()); - } - -} diff --git a/ipscan-unittest/src/net/azib/ipscan/fetchers/PingTTLFetcherTest.java b/ipscan-unittest/src/net/azib/ipscan/fetchers/PingTTLFetcherTest.java deleted file mode 100755 index 0a5e2afb..00000000 --- a/ipscan-unittest/src/net/azib/ipscan/fetchers/PingTTLFetcherTest.java +++ /dev/null @@ -1,22 +0,0 @@ -/** - * - */ -package net.azib.ipscan.fetchers; - -import net.azib.ipscan.config.Config; - -import org.junit.Before; - -/** - * PingTTLFetcherTest - * - * @author anton - */ -public class PingTTLFetcherTest extends AbstractFetcherTestCase { - - @Before - public void setUp() throws Exception { - fetcher = new PingTTLFetcher(null, Config.getGlobal()); - } - -} diff --git a/ipscan-unittest/src/net/azib/ipscan/fetchers/PortsFetcherTest.java b/ipscan-unittest/src/net/azib/ipscan/fetchers/PortsFetcherTest.java deleted file mode 100755 index 7ed3165b..00000000 --- a/ipscan-unittest/src/net/azib/ipscan/fetchers/PortsFetcherTest.java +++ /dev/null @@ -1,22 +0,0 @@ -/** - * - */ -package net.azib.ipscan.fetchers; - -import net.azib.ipscan.config.Config; - -import org.junit.Before; - -/** - * PortsFetcherTest - * - * @author anton - */ -public class PortsFetcherTest extends AbstractFetcherTestCase { - - @Before - public void setUp() throws Exception { - fetcher = new PortsFetcher(Config.getGlobal()); - } - -} diff --git a/ipscan-unittest/src/net/azib/ipscan/gui/SelectFetchersDialogTest.java b/ipscan-unittest/src/net/azib/ipscan/gui/SelectFetchersDialogTest.java deleted file mode 100755 index d0381499..00000000 --- a/ipscan-unittest/src/net/azib/ipscan/gui/SelectFetchersDialogTest.java +++ /dev/null @@ -1,35 +0,0 @@ -/** - * - */ -package net.azib.ipscan.gui; - -import static org.easymock.EasyMock.*; - -import net.azib.ipscan.fetchers.FetcherRegistry; - -import org.junit.Test; - -/** - * @author Anton Keks - * - */ -public class SelectFetchersDialogTest { - - @Test @SuppressWarnings("unchecked") - public void testSaveFetchersToRegistry() { - FetcherRegistry fetcherRegistry = createMock(FetcherRegistry.class); - fetcherRegistry.updateSelectedFetchers(aryEq(new String[] {"fetcher.ip", "fetcher.blah", "fetcher.hello"})); - replay(fetcherRegistry); - - SelectFetchersDialog selectFetchersDialog = new SelectFetchersDialog(fetcherRegistry); - - selectFetchersDialog.registeredFetcherLabelsByNames.put("IP", "fetcher.ip"); - selectFetchersDialog.registeredFetcherLabelsByNames.put("Hello", "fetcher.hello"); - selectFetchersDialog.registeredFetcherLabelsByNames.put("Blah", "fetcher.blah"); - - selectFetchersDialog.saveFetchersToRegistry(new String[] {"Blah", "Hello"}); - - verify(fetcherRegistry); - } - -} diff --git a/ipscan-unittest/src/net/azib/ipscan/gui/actions/OpenerLauncherTest.java b/ipscan-unittest/src/net/azib/ipscan/gui/actions/OpenerLauncherTest.java deleted file mode 100755 index ebf94ae4..00000000 --- a/ipscan-unittest/src/net/azib/ipscan/gui/actions/OpenerLauncherTest.java +++ /dev/null @@ -1,76 +0,0 @@ -/** - * - */ -package net.azib.ipscan.gui.actions; - -import static org.easymock.EasyMock.createMock; -import static org.easymock.EasyMock.expect; -import static org.easymock.EasyMock.replay; -import static org.easymock.EasyMock.verify; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; -import net.azib.ipscan.config.Config; -import net.azib.ipscan.config.Labels; -import net.azib.ipscan.fetchers.FetcherRegistry; -import net.azib.ipscan.gui.UserErrorException; - -import org.junit.Before; -import org.junit.Test; - -/** - * OpenerLauncherTest - * - * @author anton - */ -public class OpenerLauncherTest { - - @Before - public void setUp() { - Config.initialize(); - } - - @Test - public void testReplaceValues() { - FetcherRegistry fetcherRegistry = createMock(FetcherRegistry.class); - expect(fetcherRegistry.getSelectedFetcherIndex("fetcher.ip")).andReturn(0).times(3); - expect(fetcherRegistry.getSelectedFetcherIndex("fetcher.hostname")).andReturn(1); - expect(fetcherRegistry.getSelectedFetcherIndex("fetcher.comment")).andReturn(2); - expect(fetcherRegistry.getSelectedFetcherIndex("noSuchFetcher")).andReturn(-1); - replay(fetcherRegistry); - - OpenerLauncher ol = new OpenerLauncher(fetcherRegistry, null) { - String getScannedValue(int selectedItem, int fetcherIndex) { - switch (fetcherIndex) { - case 0: - return "127.0.0.1"; - case 1: - return "HOSTNAME"; - default: - return null; - } - } - }; - - 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)); - - 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()); - } - - verify(fetcherRegistry); - } -} diff --git a/ipscan-unittest/src/net/azib/ipscan/gui/feeders/AbstractFeederGUITest.java b/ipscan-unittest/src/net/azib/ipscan/gui/feeders/AbstractFeederGUITest.java deleted file mode 100755 index 983585c0..00000000 --- a/ipscan-unittest/src/net/azib/ipscan/gui/feeders/AbstractFeederGUITest.java +++ /dev/null @@ -1,63 +0,0 @@ -/** - * - */ -package net.azib.ipscan.gui.feeders; - -import static org.junit.Assert.*; - -import org.eclipse.swt.widgets.Shell; - -import net.azib.ipscan.feeders.Feeder; -import net.azib.ipscan.feeders.RangeFeeder; - -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -/** - * AbstractFeederGUITest - * - * @author anton - */ -public class AbstractFeederGUITest { - - private AbstractFeederGUI feederGUI; - - @BeforeClass - public static void globalSetUp() { - System.setProperty("java.library.path", "../swt/lib"); - } - - @Before - public void setUp() throws Exception { - feederGUI = new AbstractFeederGUI(new Shell()) { - - protected void initialize() { - } - - public String getFeederName() { - return "Mega Feeder"; - } - - public Feeder getFeeder() { - feeder = new RangeFeeder(); - feeder.initialize(new String[] {"127.0.0.1", "127.0.0.2"}); - return feeder; - } - - public String serialize() { - return ""; - } - - public void unserialize(String serialized) { - } - - }; - } - - @Test - public void testGetInfo() { - assertEquals("Mega Feeder: 127.0.0.1 - 127.0.0.2", feederGUI.getInfo()); - } - -} diff --git a/ipscan-unittest/ext/easymock/easymock.jar b/ipscan/ext/easymock/easymock.jar similarity index 100% rename from ipscan-unittest/ext/easymock/easymock.jar rename to ipscan/ext/easymock/easymock.jar diff --git a/ipscan-unittest/ext/emma/emma.jar b/ipscan/ext/emma/emma.jar similarity index 100% rename from ipscan-unittest/ext/emma/emma.jar rename to ipscan/ext/emma/emma.jar diff --git a/ipscan-unittest/ext/emma/emma_ant.jar b/ipscan/ext/emma/emma_ant.jar similarity index 100% rename from ipscan-unittest/ext/emma/emma_ant.jar rename to ipscan/ext/emma/emma_ant.jar diff --git a/ipscan-unittest/ext/junit/junit-4.1.jar b/ipscan/ext/junit/junit-4.1.jar similarity index 100% rename from ipscan-unittest/ext/junit/junit-4.1.jar rename to ipscan/ext/junit/junit-4.1.jar diff --git a/swt/swt-gtk.jar b/ipscan/ext/swt/swt-gtk.jar similarity index 100% rename from swt/swt-gtk.jar rename to ipscan/ext/swt/swt-gtk.jar diff --git a/swt/swt-mac.jar b/ipscan/ext/swt/swt-mac.jar similarity index 100% rename from swt/swt-mac.jar rename to ipscan/ext/swt/swt-mac.jar diff --git a/swt/swt-win32.jar b/ipscan/ext/swt/swt-win32.jar similarity index 100% rename from swt/swt-win32.jar rename to ipscan/ext/swt/swt-win32.jar