From 84d14762c5fa49304b7f253f2bfa7d36cd7cd4c5 Mon Sep 17 00:00:00 2001 From: angryziber Date: Sun, 30 Mar 2008 19:09:34 +0000 Subject: [PATCH] * value objects now have nicer names * NumericRangeList is now properly comparable git-svn-id: https://ipscan.svn.sourceforge.net/svnroot/ipscan/trunk@342 375186e5-ef17-0410-b0b6-91563547dcda --- TODO | 2 - src/net/azib/ipscan/core/Scanner.java | 8 ++-- ...dressValue.java => InetAddressHolder.java} | 8 ++-- ...tAvailableValue.java => NotAvailable.java} | 6 +-- .../{NotScannedValue.java => NotScanned.java} | 6 +-- ...icListValue.java => NumericRangeList.java} | 16 ++++++- src/net/azib/ipscan/fetchers/Fetcher.java | 6 +-- .../ipscan/fetchers/FilteredPortsFetcher.java | 8 ++-- src/net/azib/ipscan/fetchers/IPFetcher.java | 4 +- .../azib/ipscan/fetchers/PortsFetcher.java | 12 +++--- test/net/azib/ipscan/core/ScannerTest.java | 12 +++--- .../ipscan/core/ScanningResultListTest.java | 4 +- ...ueTest.java => InetAddressHolderTest.java} | 16 +++---- ...leValueTest.java => NotAvailableTest.java} | 14 +++---- ...nnedValueTest.java => NotScannedTest.java} | 14 +++---- .../core/values/NumericListValueTest.java | 33 --------------- .../core/values/NumericRangeListTest.java | 42 +++++++++++++++++++ .../ipscan/fetchers/PortsFetcherTest.java | 8 ++-- .../gui/actions/OpenerLauncherTest.java | 10 ++--- 19 files changed, 124 insertions(+), 105 deletions(-) rename src/net/azib/ipscan/core/values/{InetAddressValue.java => InetAddressHolder.java} (82%) rename src/net/azib/ipscan/core/values/{NotAvailableValue.java => NotAvailable.java} (74%) rename src/net/azib/ipscan/core/values/{NotScannedValue.java => NotScanned.java} (74%) rename src/net/azib/ipscan/core/values/{NumericListValue.java => NumericRangeList.java} (81%) rename test/net/azib/ipscan/core/values/{InetAddressValueTest.java => InetAddressHolderTest.java} (61%) rename test/net/azib/ipscan/core/values/{NotAvailableValueTest.java => NotAvailableTest.java} (53%) rename test/net/azib/ipscan/core/values/{NotScannedValueTest.java => NotScannedTest.java} (54%) delete mode 100755 test/net/azib/ipscan/core/values/NumericListValueTest.java create mode 100755 test/net/azib/ipscan/core/values/NumericRangeListTest.java diff --git a/TODO b/TODO index 1dc4aa21..ebf6bba2 100644 --- a/TODO +++ b/TODO @@ -1,8 +1,6 @@ Before 3.0: -* NAV and NSV -> enum * rename abortScanning() to something else -* getLabel() vs getId() + getName() in plugins * command-line scanning start * fetcher-specific options * multiple port support web-detect diff --git a/src/net/azib/ipscan/core/Scanner.java b/src/net/azib/ipscan/core/Scanner.java index db78bb05..56fef805 100755 --- a/src/net/azib/ipscan/core/Scanner.java +++ b/src/net/azib/ipscan/core/Scanner.java @@ -7,8 +7,8 @@ package net.azib.ipscan.core; import java.net.InetAddress; -import net.azib.ipscan.core.values.NotAvailableValue; -import net.azib.ipscan.core.values.NotScannedValue; +import net.azib.ipscan.core.values.NotAvailable; +import net.azib.ipscan.core.values.NotScanned; import net.azib.ipscan.fetchers.Fetcher; import net.azib.ipscan.fetchers.FetcherRegistry; @@ -41,14 +41,14 @@ public class Scanner { int fetcherIndex = 0; boolean isScanningInterrupted = false; for (Fetcher fetcher : fetcherRegistry.getSelectedFetchers()) { - Object value = NotScannedValue.INSTANCE; + Object value = NotScanned.VALUE; if (!scanningSubject.isAddressScanningAborted() && !isScanningInterrupted) { // run the fetcher value = fetcher.scan(scanningSubject); // check if scanning was interrupted isScanningInterrupted = Thread.currentThread().isInterrupted(); if (value == null) - value = isScanningInterrupted ? NotScannedValue.INSTANCE : NotAvailableValue.INSTANCE; + value = isScanningInterrupted ? NotScanned.VALUE : NotAvailable.VALUE; } // store the value result.setValue(fetcherIndex, value); diff --git a/src/net/azib/ipscan/core/values/InetAddressValue.java b/src/net/azib/ipscan/core/values/InetAddressHolder.java similarity index 82% rename from src/net/azib/ipscan/core/values/InetAddressValue.java rename to src/net/azib/ipscan/core/values/InetAddressHolder.java index 04ff12d9..72a677ab 100644 --- a/src/net/azib/ipscan/core/values/InetAddressValue.java +++ b/src/net/azib/ipscan/core/values/InetAddressHolder.java @@ -13,17 +13,17 @@ import java.net.InetAddress; * * @author Anton Keks */ -public class InetAddressValue implements Comparable { +public class InetAddressHolder implements Comparable { private String s; private byte[] a; - public InetAddressValue(InetAddress address) { + public InetAddressHolder(InetAddress address) { s = address.getHostAddress(); a = address.getAddress(); } - public int compareTo(InetAddressValue that) { + public int compareTo(InetAddressHolder that) { byte[] b1 = this.a; byte[] b2 = that.a; @@ -59,7 +59,7 @@ public class InetAddressValue implements Comparable { return false; if (getClass() != obj.getClass()) return false; - final InetAddressValue other = (InetAddressValue) obj; + final InetAddressHolder other = (InetAddressHolder) obj; if (s == null) { if (other.s != null) return false; diff --git a/src/net/azib/ipscan/core/values/NotAvailableValue.java b/src/net/azib/ipscan/core/values/NotAvailable.java similarity index 74% rename from src/net/azib/ipscan/core/values/NotAvailableValue.java rename to src/net/azib/ipscan/core/values/NotAvailable.java index c1c9e026..2224e373 100755 --- a/src/net/azib/ipscan/core/values/NotAvailableValue.java +++ b/src/net/azib/ipscan/core/values/NotAvailable.java @@ -11,11 +11,11 @@ import net.azib.ipscan.config.Config; * * @author Anton Keks */ -public class NotAvailableValue implements Comparable { +public class NotAvailable implements Comparable { - public static final NotAvailableValue INSTANCE = new NotAvailableValue(); + public static final NotAvailable VALUE = new NotAvailable(); - private NotAvailableValue() {} + private NotAvailable() {} /** * Displays a user-friendly text string :-) diff --git a/src/net/azib/ipscan/core/values/NotScannedValue.java b/src/net/azib/ipscan/core/values/NotScanned.java similarity index 74% rename from src/net/azib/ipscan/core/values/NotScannedValue.java rename to src/net/azib/ipscan/core/values/NotScanned.java index 6d27abe0..e2371bdc 100755 --- a/src/net/azib/ipscan/core/values/NotScannedValue.java +++ b/src/net/azib/ipscan/core/values/NotScanned.java @@ -11,11 +11,11 @@ import net.azib.ipscan.config.Config; * * @author Anton Keks */ -public class NotScannedValue implements Comparable { +public class NotScanned implements Comparable { - public static final NotScannedValue INSTANCE = new NotScannedValue(); + public static final NotScanned VALUE = new NotScanned(); - private NotScannedValue() {} + private NotScanned() {} /** * Displays a user-friendly text string :-) diff --git a/src/net/azib/ipscan/core/values/NumericListValue.java b/src/net/azib/ipscan/core/values/NumericRangeList.java similarity index 81% rename from src/net/azib/ipscan/core/values/NumericListValue.java rename to src/net/azib/ipscan/core/values/NumericRangeList.java index f3a5cc19..b6406667 100755 --- a/src/net/azib/ipscan/core/values/NumericListValue.java +++ b/src/net/azib/ipscan/core/values/NumericRangeList.java @@ -16,7 +16,7 @@ import java.util.Collection; * * @author Anton Keks */ -public class NumericListValue { +public class NumericRangeList implements Comparable { private static final long serialVersionUID = 1L; @@ -28,7 +28,7 @@ public class NumericListValue { * @param numbers Collections of Numbers (must be sorted for ranges to work) * @param displayAsRanges whether toString() outputs all number or their ranges */ - public NumericListValue(Collection numbers, boolean displayAsRanges) { + public NumericRangeList(Collection numbers, boolean displayAsRanges) { // copy numbers to an array (unfortunately toArray() cannot be used because int[] is not an Object[]) this.numbers = new int[numbers.size()]; int c = 0; @@ -81,4 +81,16 @@ public class NumericListValue { return sb.toString(); } + + public int compareTo(NumericRangeList that) { + // compare length + int result = this.numbers.length - that.numbers.length; + if (result == 0) { + // compare contents if length is the same + for (int i = 0; i < this.numbers.length && result == 0; i++) { + result = this.numbers[i] - that.numbers[i]; + } + } + return result; + } } diff --git a/src/net/azib/ipscan/fetchers/Fetcher.java b/src/net/azib/ipscan/fetchers/Fetcher.java index 56938953..d18182dc 100755 --- a/src/net/azib/ipscan/fetchers/Fetcher.java +++ b/src/net/azib/ipscan/fetchers/Fetcher.java @@ -6,8 +6,8 @@ package net.azib.ipscan.fetchers; import net.azib.ipscan.core.ScanningSubject; import net.azib.ipscan.core.plugins.Pluggable; -import net.azib.ipscan.core.values.NotAvailableValue; -import net.azib.ipscan.core.values.NotScannedValue; +import net.azib.ipscan.core.values.NotAvailable; +import net.azib.ipscan.core.values.NotScanned; /** * Interface of all IP Fetchers. @@ -41,7 +41,7 @@ public interface Fetcher extends Cloneable, Pluggable { * Does the actual fetching. * @param subject the scanning subject, containing an IP address * @return the fetched data (a String in most cases), null in case of any error. - * Special values may also be returned, such as {@link NotAvailableValue} or {@link NotScannedValue} + * Special values may also be returned, such as {@link NotAvailable} or {@link NotScanned} */ public Object scan(ScanningSubject subject); diff --git a/src/net/azib/ipscan/fetchers/FilteredPortsFetcher.java b/src/net/azib/ipscan/fetchers/FilteredPortsFetcher.java index 3e48281a..dfee5d8f 100755 --- a/src/net/azib/ipscan/fetchers/FilteredPortsFetcher.java +++ b/src/net/azib/ipscan/fetchers/FilteredPortsFetcher.java @@ -9,8 +9,8 @@ import java.util.SortedSet; import net.azib.ipscan.config.ScannerConfig; import net.azib.ipscan.core.ScanningSubject; -import net.azib.ipscan.core.values.NotScannedValue; -import net.azib.ipscan.core.values.NumericListValue; +import net.azib.ipscan.core.values.NotScanned; +import net.azib.ipscan.core.values.NumericRangeList; /** * FilteredPortsFetcher uses the scanning results of PortsFetcher to display filtered ports. @@ -30,9 +30,9 @@ public class FilteredPortsFetcher extends PortsFetcher { public Object scan(ScanningSubject subject) { boolean portsScanned = scanPorts(subject); if (!portsScanned) - return NotScannedValue.INSTANCE; + return NotScanned.VALUE; SortedSet filteredPorts = getFilteredPorts(subject); - return filteredPorts.size() > 0 ? new NumericListValue(filteredPorts, displayAsRanges) : null; + return filteredPorts.size() > 0 ? new NumericRangeList(filteredPorts, displayAsRanges) : null; } } diff --git a/src/net/azib/ipscan/fetchers/IPFetcher.java b/src/net/azib/ipscan/fetchers/IPFetcher.java index c3ced100..9d9b6ce3 100755 --- a/src/net/azib/ipscan/fetchers/IPFetcher.java +++ b/src/net/azib/ipscan/fetchers/IPFetcher.java @@ -5,7 +5,7 @@ package net.azib.ipscan.fetchers; import net.azib.ipscan.core.ScanningSubject; -import net.azib.ipscan.core.values.InetAddressValue; +import net.azib.ipscan.core.values.InetAddressHolder; /** * Dummy fetcher, which is able to return the textual representation @@ -22,7 +22,7 @@ public class IPFetcher extends AbstractFetcher { } public Object scan(ScanningSubject subject) { - return new InetAddressValue(subject.getAddress()); + return new InetAddressHolder(subject.getAddress()); } } diff --git a/src/net/azib/ipscan/fetchers/PortsFetcher.java b/src/net/azib/ipscan/fetchers/PortsFetcher.java index 5fc69f44..7cf57261 100755 --- a/src/net/azib/ipscan/fetchers/PortsFetcher.java +++ b/src/net/azib/ipscan/fetchers/PortsFetcher.java @@ -17,9 +17,9 @@ import net.azib.ipscan.config.ScannerConfig; import net.azib.ipscan.core.PortIterator; import net.azib.ipscan.core.ScanningSubject; import net.azib.ipscan.core.ScanningResult.ResultType; -import net.azib.ipscan.core.values.NotAvailableValue; -import net.azib.ipscan.core.values.NotScannedValue; -import net.azib.ipscan.core.values.NumericListValue; +import net.azib.ipscan.core.values.NotAvailable; +import net.azib.ipscan.core.values.NotScanned; +import net.azib.ipscan.core.values.NumericRangeList; /** * PortsFetcher scans TCP ports. @@ -51,7 +51,7 @@ public class PortsFetcher extends AbstractFetcher { @Override public String getFullName() { int numPorts = new PortIterator(config.portString).size(); - return getName() + " " + (numPorts > 0 ? "[" + numPorts + "]" : NotAvailableValue.INSTANCE); + return getName() + " " + (numPorts > 0 ? "[" + numPorts + "]" : NotAvailable.VALUE); } /** @@ -142,14 +142,14 @@ public class PortsFetcher extends AbstractFetcher { public Object scan(ScanningSubject subject) { boolean portsScanned = scanPorts(subject); if (!portsScanned) - return NotScannedValue.INSTANCE; + return NotScanned.VALUE; SortedSet openPorts = getOpenPorts(subject); boolean portsFound = openPorts.size() > 0; if (portsFound) { subject.setResultType(ResultType.WITH_PORTS); } - return portsFound ? new NumericListValue(openPorts, displayAsRanges) : null; + return portsFound ? new NumericRangeList(openPorts, displayAsRanges) : null; } public void init() { diff --git a/test/net/azib/ipscan/core/ScannerTest.java b/test/net/azib/ipscan/core/ScannerTest.java index 2030a90f..7b2fbe90 100755 --- a/test/net/azib/ipscan/core/ScannerTest.java +++ b/test/net/azib/ipscan/core/ScannerTest.java @@ -18,8 +18,8 @@ import java.util.HashSet; import java.util.Set; import net.azib.ipscan.core.ScanningResult.ResultType; -import net.azib.ipscan.core.values.NotAvailableValue; -import net.azib.ipscan.core.values.NotScannedValue; +import net.azib.ipscan.core.values.NotAvailable; +import net.azib.ipscan.core.values.NotScanned; import net.azib.ipscan.fetchers.AbstractFetcher; import net.azib.ipscan.fetchers.Fetcher; import net.azib.ipscan.fetchers.FetcherRegistry; @@ -66,9 +66,9 @@ public class ScannerTest { assertEquals(InetAddress.getLocalHost(), scanningResult.getAddress()); assertEquals(4, scanningResult.getValues().size()); assertEquals("blah", scanningResult.getValues().get(0)); - assertEquals(NotAvailableValue.INSTANCE, scanningResult.getValues().get(1)); + assertEquals(NotAvailable.VALUE, scanningResult.getValues().get(1)); assertEquals("666 ms", scanningResult.getValues().get(2)); - assertEquals(NotScannedValue.INSTANCE, scanningResult.getValues().get(3)); + assertEquals(NotScanned.VALUE, scanningResult.getValues().get(3)); } @Test @@ -88,8 +88,8 @@ public class ScannerTest { assertEquals(InetAddress.getLocalHost(), scanningResult.getAddress()); assertEquals(3, scanningResult.getValues().size()); assertEquals("plainValue", scanningResult.getValues().get(0)); - assertEquals(NotScannedValue.INSTANCE, scanningResult.getValues().get(1)); - assertEquals(NotScannedValue.INSTANCE, scanningResult.getValues().get(2)); + assertEquals(NotScanned.VALUE, scanningResult.getValues().get(1)); + assertEquals(NotScanned.VALUE, scanningResult.getValues().get(2)); // reset interrupted flag assertTrue(Thread.interrupted()); diff --git a/test/net/azib/ipscan/core/ScanningResultListTest.java b/test/net/azib/ipscan/core/ScanningResultListTest.java index 7c494d5d..1cb865b9 100755 --- a/test/net/azib/ipscan/core/ScanningResultListTest.java +++ b/test/net/azib/ipscan/core/ScanningResultListTest.java @@ -26,7 +26,7 @@ import net.azib.ipscan.core.ScanningResultList.ScanInfo; import net.azib.ipscan.core.ScanningResultList.StopScanningListener; import net.azib.ipscan.core.state.ScanningState; import net.azib.ipscan.core.state.StateMachine; -import net.azib.ipscan.core.values.NotScannedValue; +import net.azib.ipscan.core.values.NotScanned; import net.azib.ipscan.feeders.Feeder; import net.azib.ipscan.fetchers.Fetcher; import net.azib.ipscan.fetchers.FetcherRegistry; @@ -310,7 +310,7 @@ public class ScanningResultListTest { @Test public void testFindText() throws Exception { scanningResults.registerAtIndex(0, scanningResults.createResult(InetAddress.getByName("127.9.9.1"))); - scanningResults.getResult(0).setValue(1, NotScannedValue.INSTANCE); + scanningResults.getResult(0).setValue(1, NotScanned.VALUE); scanningResults.registerAtIndex(1, scanningResults.createResult(InetAddress.getByName("127.9.9.2"))); scanningResults.getResult(1).setValue(1, new Long(123456789L)); scanningResults.registerAtIndex(2, scanningResults.createResult(InetAddress.getByName("127.9.9.3"))); diff --git a/test/net/azib/ipscan/core/values/InetAddressValueTest.java b/test/net/azib/ipscan/core/values/InetAddressHolderTest.java similarity index 61% rename from test/net/azib/ipscan/core/values/InetAddressValueTest.java rename to test/net/azib/ipscan/core/values/InetAddressHolderTest.java index ccb1092c..9f74addc 100644 --- a/test/net/azib/ipscan/core/values/InetAddressValueTest.java +++ b/test/net/azib/ipscan/core/values/InetAddressHolderTest.java @@ -17,19 +17,19 @@ import org.junit.Test; * * @author Anton Keks */ -public class InetAddressValueTest { +public class InetAddressHolderTest { @Test public void testToString() throws Exception { - InetAddressValue av = new InetAddressValue(InetAddress.getLocalHost()); + InetAddressHolder av = new InetAddressHolder(InetAddress.getLocalHost()); assertEquals(InetAddress.getLocalHost().getHostAddress(), av.toString()); } @Test public void testCompareTo() throws Exception { - InetAddressValue av2 = new InetAddressValue(InetAddress.getByName("192.168.0.2")); - InetAddressValue av10 = new InetAddressValue(InetAddress.getByName("192.168.0.10")); - InetAddressValue av127 = new InetAddressValue(InetAddress.getByName("192.168.0.127")); - InetAddressValue av253 = new InetAddressValue(InetAddress.getByName("192.168.0.253")); + InetAddressHolder av2 = new InetAddressHolder(InetAddress.getByName("192.168.0.2")); + InetAddressHolder av10 = new InetAddressHolder(InetAddress.getByName("192.168.0.10")); + InetAddressHolder av127 = new InetAddressHolder(InetAddress.getByName("192.168.0.127")); + InetAddressHolder av253 = new InetAddressHolder(InetAddress.getByName("192.168.0.253")); assertEquals(-1, av2.compareTo(av10)); assertEquals(1, av10.compareTo(av2)); assertEquals(0, av2.compareTo(av2)); @@ -42,8 +42,8 @@ public class InetAddressValueTest { @Test public void testEqualsHashCode() throws Exception { - InetAddressValue av1 = new InetAddressValue(InetAddress.getByName("192.168.0.2")); - InetAddressValue av2 = new InetAddressValue(InetAddress.getByAddress(new byte[] {(byte)192, (byte)168, 0, 2})); + InetAddressHolder av1 = new InetAddressHolder(InetAddress.getByName("192.168.0.2")); + InetAddressHolder av2 = new InetAddressHolder(InetAddress.getByAddress(new byte[] {(byte)192, (byte)168, 0, 2})); assertEquals(av1, av2); assertEquals(av1.hashCode(), av2.hashCode()); assertFalse(av1.equals(null)); diff --git a/test/net/azib/ipscan/core/values/NotAvailableValueTest.java b/test/net/azib/ipscan/core/values/NotAvailableTest.java similarity index 53% rename from test/net/azib/ipscan/core/values/NotAvailableValueTest.java rename to test/net/azib/ipscan/core/values/NotAvailableTest.java index 2a222c0a..ebc63e10 100755 --- a/test/net/azib/ipscan/core/values/NotAvailableValueTest.java +++ b/test/net/azib/ipscan/core/values/NotAvailableTest.java @@ -14,23 +14,23 @@ import org.junit.Test; * * @author Anton Keks */ -public class NotAvailableValueTest { +public class NotAvailableTest { @Test public void testEquals() throws Exception { - assertEquals(NotAvailableValue.INSTANCE, NotAvailableValue.INSTANCE); + assertEquals(NotAvailable.VALUE, NotAvailable.VALUE); } @Test public void testToString() throws Exception { - assertEquals(Config.getConfig().forScanner().notAvailableText, NotAvailableValue.INSTANCE.toString()); + assertEquals(Config.getConfig().forScanner().notAvailableText, NotAvailable.VALUE.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)); + assertTrue(Comparable.class.isAssignableFrom(NotAvailable.class)); + assertEquals(0, NotAvailable.VALUE.compareTo(NotAvailable.VALUE)); + assertEquals(-1, NotAvailable.VALUE.compareTo("Hello")); + assertEquals(1, NotAvailable.VALUE.compareTo(null)); } } diff --git a/test/net/azib/ipscan/core/values/NotScannedValueTest.java b/test/net/azib/ipscan/core/values/NotScannedTest.java similarity index 54% rename from test/net/azib/ipscan/core/values/NotScannedValueTest.java rename to test/net/azib/ipscan/core/values/NotScannedTest.java index c73f24ab..4dc00980 100755 --- a/test/net/azib/ipscan/core/values/NotScannedValueTest.java +++ b/test/net/azib/ipscan/core/values/NotScannedTest.java @@ -14,24 +14,24 @@ import org.junit.Test; * * @author Anton Keks */ -public class NotScannedValueTest { +public class NotScannedTest { @Test public void testEquals() throws Exception { - assertEquals(NotScannedValue.INSTANCE, NotScannedValue.INSTANCE); + assertEquals(NotScanned.VALUE, NotScanned.VALUE); } @Test public void testToString() throws Exception { - assertEquals(Config.getConfig().forScanner().notScannedText, NotScannedValue.INSTANCE.toString()); + assertEquals(Config.getConfig().forScanner().notScannedText, NotScanned.VALUE.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)); + assertTrue(Comparable.class.isAssignableFrom(NotScanned.class)); + assertEquals(0, NotScanned.VALUE.compareTo(NotScanned.VALUE)); + assertEquals(-1, NotScanned.VALUE.compareTo("Hello")); + assertEquals(1, NotScanned.VALUE.compareTo(null)); } } diff --git a/test/net/azib/ipscan/core/values/NumericListValueTest.java b/test/net/azib/ipscan/core/values/NumericListValueTest.java deleted file mode 100755 index c3e56ee6..00000000 --- a/test/net/azib/ipscan/core/values/NumericListValueTest.java +++ /dev/null @@ -1,33 +0,0 @@ -/** - * This file is a part of Angry IP Scanner source code, - * see http://www.azib.net/ for more information. - * Licensed under GPLv2. - */ -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.emptyList(), true).toString()); - assertEquals("1", new NumericListValue(Arrays.asList(1), true).toString()); - assertEquals("1,2", new NumericListValue(Arrays.asList(1, 2), true).toString()); - assertEquals("1-3", new NumericListValue(Arrays.asList(1, 2, 3), true).toString()); - assertEquals("1-3", new NumericListValue(new TreeSet(Arrays.asList(2, 3, 1)), true).toString()); - assertEquals("1,2,3", new NumericListValue(Arrays.asList(1, 2, 3), false).toString()); - assertEquals("1,5,6,15", new NumericListValue(Arrays.asList(1, 5, 6, 15), true).toString()); - assertEquals("1,5-8,15", new NumericListValue(Arrays.asList(1, 5, 6, 7, 8, 15), true).toString()); - assertEquals("103,85,89,1", new NumericListValue(Arrays.asList(103, 85, 89, 1), true).toString()); - } -} diff --git a/test/net/azib/ipscan/core/values/NumericRangeListTest.java b/test/net/azib/ipscan/core/values/NumericRangeListTest.java new file mode 100755 index 00000000..60889ac7 --- /dev/null +++ b/test/net/azib/ipscan/core/values/NumericRangeListTest.java @@ -0,0 +1,42 @@ +/** + * This file is a part of Angry IP Scanner source code, + * see http://www.azib.net/ for more information. + * Licensed under GPLv2. + */ +package net.azib.ipscan.core.values; + +import static org.junit.Assert.*; + +import java.util.Arrays; +import java.util.Collections; +import java.util.TreeSet; + +import org.junit.Test; + +/** + * @author Anton Keks + */ +public class NumericRangeListTest { + + @Test + public void testToString() { + assertEquals("", new NumericRangeList(Collections.emptyList(), true).toString()); + assertEquals("1", new NumericRangeList(Arrays.asList(1), true).toString()); + assertEquals("1,2", new NumericRangeList(Arrays.asList(1, 2), true).toString()); + assertEquals("1-3", new NumericRangeList(Arrays.asList(1, 2, 3), true).toString()); + assertEquals("1-3", new NumericRangeList(new TreeSet(Arrays.asList(2, 3, 1)), true).toString()); + assertEquals("1,2,3", new NumericRangeList(Arrays.asList(1, 2, 3), false).toString()); + assertEquals("1,5,6,15", new NumericRangeList(Arrays.asList(1, 5, 6, 15), true).toString()); + assertEquals("1,5-8,15", new NumericRangeList(Arrays.asList(1, 5, 6, 7, 8, 15), true).toString()); + assertEquals("103,85,89,1", new NumericRangeList(Arrays.asList(103, 85, 89, 1), true).toString()); + } + + @Test + public void testCompateTo() throws Exception { + assertTrue(new NumericRangeList(Arrays.asList(22), false).compareTo(new NumericRangeList(Arrays.asList(80), false)) < 0); + assertTrue(new NumericRangeList(Arrays.asList(80), false).compareTo(new NumericRangeList(Arrays.asList(22), false)) > 0); + assertTrue(new NumericRangeList(Arrays.asList(255), false).compareTo(new NumericRangeList(Arrays.asList(255), false)) == 0); + assertTrue(new NumericRangeList(Arrays.asList(1, 2), false).compareTo(new NumericRangeList(Arrays.asList(8080), false)) > 0); + assertTrue(new NumericRangeList(Arrays.asList(22, 25, 27, 28), false).compareTo(new NumericRangeList(Arrays.asList(22, 25, 26, 300), false)) > 0); + } +} diff --git a/test/net/azib/ipscan/fetchers/PortsFetcherTest.java b/test/net/azib/ipscan/fetchers/PortsFetcherTest.java index 95254099..660f25a8 100755 --- a/test/net/azib/ipscan/fetchers/PortsFetcherTest.java +++ b/test/net/azib/ipscan/fetchers/PortsFetcherTest.java @@ -13,8 +13,8 @@ import java.net.Socket; import net.azib.ipscan.config.ScannerConfig; import net.azib.ipscan.core.ScanningSubject; -import net.azib.ipscan.core.values.NotAvailableValue; -import net.azib.ipscan.core.values.NumericListValue; +import net.azib.ipscan.core.values.NotAvailable; +import net.azib.ipscan.core.values.NumericRangeList; import org.junit.Before; import org.junit.Test; @@ -37,7 +37,7 @@ public class PortsFetcherTest extends AbstractFetcherTestCase { @Test public void numberOfPortsInFullName() throws Exception { config.portString = ""; - assertEquals(fetcher.getName() + " " + NotAvailableValue.INSTANCE, fetcher.getFullName()); + assertEquals(fetcher.getName() + " " + NotAvailable.VALUE, fetcher.getFullName()); config.portString = "1-3"; assertEquals(fetcher.getName() + " [3]", fetcher.getFullName()); @@ -107,7 +107,7 @@ public class PortsFetcherTest extends AbstractFetcherTestCase { synchronized (server) { server.wait(); } - NumericListValue value = (NumericListValue) fetcher.scan(new ScanningSubject(InetAddress.getLocalHost())); + NumericRangeList value = (NumericRangeList) fetcher.scan(new ScanningSubject(InetAddress.getLocalHost())); assertEquals(config.portString, value.toString()); fetcher.cleanup(); diff --git a/test/net/azib/ipscan/gui/actions/OpenerLauncherTest.java b/test/net/azib/ipscan/gui/actions/OpenerLauncherTest.java index 5a5f2595..c46d632a 100755 --- a/test/net/azib/ipscan/gui/actions/OpenerLauncherTest.java +++ b/test/net/azib/ipscan/gui/actions/OpenerLauncherTest.java @@ -18,8 +18,8 @@ import net.azib.ipscan.config.Labels; import net.azib.ipscan.core.ScanningResult; import net.azib.ipscan.core.ScanningResultList; import net.azib.ipscan.core.UserErrorException; -import net.azib.ipscan.core.values.InetAddressValue; -import net.azib.ipscan.core.values.NotAvailableValue; +import net.azib.ipscan.core.values.InetAddressHolder; +import net.azib.ipscan.core.values.NotAvailable; import net.azib.ipscan.feeders.Feeder; import net.azib.ipscan.fetchers.Fetcher; import net.azib.ipscan.fetchers.FetcherRegistry; @@ -47,9 +47,9 @@ public class OpenerLauncherTest { ScanningResultList scanningResults = new ScanningResultList(fetcherRegistry); scanningResults.initNewScan(createMockFeeder("info")); ScanningResult result = scanningResults.createResult(InetAddress.getByName("127.0.0.1")); - result.setValue(0, new InetAddressValue(InetAddress.getByName("127.0.0.1"))); + result.setValue(0, new InetAddressHolder(InetAddress.getByName("127.0.0.1"))); result.setValue(1, "HOSTNAME"); - result.setValue(2, NotAvailableValue.INSTANCE); + result.setValue(2, NotAvailable.VALUE); scanningResults.registerAtIndex(0, result); OpenerLauncher ol = new OpenerLauncher(fetcherRegistry, scanningResults); @@ -57,7 +57,7 @@ public class OpenerLauncherTest { assertEquals("\\\\127.0.0.1", ol.prepareOpenerStringForItem("\\\\${fetcher.ip}", 0)); assertEquals("HOSTNAME$$$127.0.0.1xxx${}", ol.prepareOpenerStringForItem("${fetcher.hostname}$$$${fetcher.ip}xxx${}", 0)); assertEquals("http://127.0.0.1:80/www", ol.prepareOpenerStringForItem("http://${fetcher.ip}:80/www", 0)); - assertEquals(NotAvailableValue.INSTANCE.toString() + ", xx", ol.prepareOpenerStringForItem("${fetcher.ping}, xx", 0)); + assertEquals(NotAvailable.VALUE.toString() + ", xx", ol.prepareOpenerStringForItem("${fetcher.ping}, xx", 0)); try { ol.prepareOpenerStringForItem("${noSuchFetcher}", 0);