Changed tas to spaces
This commit is contained in:
parent
a938b70d57
commit
b1c53d88ae
196 changed files with 14016 additions and 14035 deletions
|
|
@ -31,24 +31,24 @@ import static org.junit.Assert.assertEquals;
|
|||
|
||||
|
||||
public class EncrypterTest {
|
||||
public static final String data = "Hello there, wats yor name, my is a secret, 123456789";
|
||||
public static final String data = "Hello there, wats yor name, my is a secret, 123456789";
|
||||
public static final String key = "abcdefghijklmnopqrstuvwxyz";
|
||||
|
||||
|
||||
@Test
|
||||
public void encryptDES() throws Exception {
|
||||
Encrypter.randomizeSalt();
|
||||
Encrypter encrypter = new Encrypter(key, Algorithm.DES);
|
||||
Encrypter decrypter = new Encrypter(key, Algorithm.DES);
|
||||
@Test
|
||||
public void encryptDES() throws Exception {
|
||||
Encrypter.randomizeSalt();
|
||||
Encrypter encrypter = new Encrypter(key, Algorithm.DES);
|
||||
Encrypter decrypter = new Encrypter(key, Algorithm.DES);
|
||||
|
||||
assertEquals(data, encryptDecrypt(encrypter, decrypter, data));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void encryptBLOWFISH() throws Exception {
|
||||
Encrypter.randomizeSalt();
|
||||
@Test
|
||||
public void encryptBLOWFISH() throws Exception {
|
||||
Encrypter.randomizeSalt();
|
||||
Encrypter encrypter = new Encrypter(Algorithm.Blowfish);
|
||||
Encrypter.randomizeSalt();
|
||||
Encrypter.randomizeSalt();
|
||||
Encrypter decrypter = new Encrypter(encrypter.getKey());
|
||||
|
||||
assertEquals(data, encryptDecrypt(encrypter, decrypter, data));
|
||||
|
|
|
|||
|
|
@ -30,22 +30,22 @@ import static org.junit.Assert.assertEquals;
|
|||
|
||||
|
||||
public class HasherTest {
|
||||
|
||||
@Test
|
||||
public void MD5Test(){
|
||||
assertEquals(Hasher.MD5("AAAABBBB"), "9da4fc50e09e5eeb8ae8149ef4f23792");
|
||||
assertEquals(Hasher.MD5("qwerty12345"), "85064efb60a9601805dcea56ec5402f7");
|
||||
assertEquals(Hasher.MD5("123456789"), "25f9e794323b453885f5181f1b624d0b");
|
||||
//assertEquals(Hasher.MD5(".,<>|!#<23>%&/()=?"), "20d5cda029514fa49a8bbe854a539847");
|
||||
assertEquals(Hasher.MD5("Test45"), "fee43a4c9d88769e14ec6a1d8b80f2e7");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void SHA1Test(){
|
||||
assertEquals(Hasher.SHA1("AAAABBBB"), "7cd188ef3a9ea7fa0ee9c62c168709695460f5c0");
|
||||
assertEquals(Hasher.SHA1("qwerty12345"), "4e17a448e043206801b95de317e07c839770c8b8");
|
||||
assertEquals(Hasher.SHA1("123456789"), "f7c3bc1d808e04732adf679965ccc34ca7ae3441");
|
||||
//assertEquals(Hasher.SHA1(".,<>|!#<23>%&/()=?"), "6b3de029cdb367bb365d5154a197294ee590a77a");
|
||||
assertEquals(Hasher.SHA1("Test45"), "9194c6e64a6801e24e63a924d5843a46428d2b3a");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void MD5Test(){
|
||||
assertEquals(Hasher.MD5("AAAABBBB"), "9da4fc50e09e5eeb8ae8149ef4f23792");
|
||||
assertEquals(Hasher.MD5("qwerty12345"), "85064efb60a9601805dcea56ec5402f7");
|
||||
assertEquals(Hasher.MD5("123456789"), "25f9e794323b453885f5181f1b624d0b");
|
||||
//assertEquals(Hasher.MD5(".,<>|!#<23>%&/()=?"), "20d5cda029514fa49a8bbe854a539847");
|
||||
assertEquals(Hasher.MD5("Test45"), "fee43a4c9d88769e14ec6a1d8b80f2e7");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void SHA1Test(){
|
||||
assertEquals(Hasher.SHA1("AAAABBBB"), "7cd188ef3a9ea7fa0ee9c62c168709695460f5c0");
|
||||
assertEquals(Hasher.SHA1("qwerty12345"), "4e17a448e043206801b95de317e07c839770c8b8");
|
||||
assertEquals(Hasher.SHA1("123456789"), "f7c3bc1d808e04732adf679965ccc34ca7ae3441");
|
||||
//assertEquals(Hasher.SHA1(".,<>|!#<23>%&/()=?"), "6b3de029cdb367bb365d5154a197294ee590a77a");
|
||||
assertEquals(Hasher.SHA1("Test45"), "9194c6e64a6801e24e63a924d5843a46428d2b3a");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,50 +33,50 @@ import static org.junit.Assert.assertEquals;
|
|||
|
||||
public class StringUtilTest {
|
||||
|
||||
@Test
|
||||
public void formatByteSizeToStringTest() {
|
||||
assertEquals( "100.0 B", StringUtil.formatByteSizeToString(100) );
|
||||
assertEquals( "9.7 kB", StringUtil.formatByteSizeToString(10000) );
|
||||
}
|
||||
@Test
|
||||
public void formatByteSizeToStringTest() {
|
||||
assertEquals( "100.0 B", StringUtil.formatByteSizeToString(100) );
|
||||
assertEquals( "9.7 kB", StringUtil.formatByteSizeToString(10000) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void formatTimeToStringTest() {
|
||||
assertEquals( "1 sec ", StringUtil.formatTimeToString( 1000 ) );
|
||||
assertEquals( "1 month 1 day 1 hour 1 min 1 sec 1 milisec ",
|
||||
StringUtil.formatTimeToString( 2629743830l+86400000+3600000+60000+1000+1 ) );
|
||||
assertEquals( "2 months 2 days 2 hours 2 min 2 sec 2 milisec ",
|
||||
StringUtil.formatTimeToString( (2629743830l+86400000+3600000+60000+1000+1)*2 ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void trimTest() {
|
||||
assertEquals( "", StringUtil.trim("", ' ') );
|
||||
assertEquals( "aa", StringUtil.trim(" aa ", ' ') );
|
||||
assertEquals( "aa", StringUtil.trim("aa ", ' ') );
|
||||
assertEquals( "aa", StringUtil.trim(" aa", ' ') );
|
||||
assertEquals( "", StringUtil.trim(" aa ", 'a') );
|
||||
assertEquals( "aa", StringUtil.trim("\u0010 aa ", ' ') );
|
||||
assertEquals( "aa", StringUtil.trim("\n\naa\n\t", ' ') );
|
||||
assertEquals( "aa", StringUtil.trim("\"aa\"", '\"') );
|
||||
}
|
||||
@Test
|
||||
public void formatTimeToStringTest() {
|
||||
assertEquals( "1 sec ", StringUtil.formatTimeToString( 1000 ) );
|
||||
assertEquals( "1 month 1 day 1 hour 1 min 1 sec 1 milisec ",
|
||||
StringUtil.formatTimeToString( 2629743830l+86400000+3600000+60000+1000+1 ) );
|
||||
assertEquals( "2 months 2 days 2 hours 2 min 2 sec 2 milisec ",
|
||||
StringUtil.formatTimeToString( (2629743830l+86400000+3600000+60000+1000+1)*2 ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void trimQuotesTest() {
|
||||
assertEquals( "", StringUtil.trimQuotes("") );
|
||||
assertEquals( "\"", StringUtil.trimQuotes("\"") );
|
||||
assertEquals( "", StringUtil.trimQuotes("\"\"") );
|
||||
assertEquals( "\"aa", StringUtil.trimQuotes("\"aa") );
|
||||
assertEquals( "aa\"", StringUtil.trimQuotes("aa\"") );
|
||||
assertEquals( "aa", StringUtil.trimQuotes("\"aa\"") );
|
||||
}
|
||||
@Test
|
||||
public void trimTest() {
|
||||
assertEquals( "", StringUtil.trim("", ' ') );
|
||||
assertEquals( "aa", StringUtil.trim(" aa ", ' ') );
|
||||
assertEquals( "aa", StringUtil.trim("aa ", ' ') );
|
||||
assertEquals( "aa", StringUtil.trim(" aa", ' ') );
|
||||
assertEquals( "", StringUtil.trim(" aa ", 'a') );
|
||||
assertEquals( "aa", StringUtil.trim("\u0010 aa ", ' ') );
|
||||
assertEquals( "aa", StringUtil.trim("\n\naa\n\t", ' ') );
|
||||
assertEquals( "aa", StringUtil.trim("\"aa\"", '\"') );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void joinTest(){
|
||||
assertEquals("", StringUtil.join(",", Arrays.asList()));
|
||||
assertEquals("1,2,3,4,5", StringUtil.join(",", 1,2,3,4,5));
|
||||
assertEquals("1,2,3,4,5", StringUtil.join(",", Arrays.asList(1,2,3,4,5)));
|
||||
@Test
|
||||
public void trimQuotesTest() {
|
||||
assertEquals( "", StringUtil.trimQuotes("") );
|
||||
assertEquals( "\"", StringUtil.trimQuotes("\"") );
|
||||
assertEquals( "", StringUtil.trimQuotes("\"\"") );
|
||||
assertEquals( "\"aa", StringUtil.trimQuotes("\"aa") );
|
||||
assertEquals( "aa\"", StringUtil.trimQuotes("aa\"") );
|
||||
assertEquals( "aa", StringUtil.trimQuotes("\"aa\"") );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void joinTest(){
|
||||
assertEquals("", StringUtil.join(",", Arrays.asList()));
|
||||
assertEquals("1,2,3,4,5", StringUtil.join(",", 1,2,3,4,5));
|
||||
assertEquals("1,2,3,4,5", StringUtil.join(",", Arrays.asList(1,2,3,4,5)));
|
||||
assertEquals("animal,monkey,dog", StringUtil.join(",", "animal", "monkey", "dog"));
|
||||
assertEquals("animal,monkey,dog", StringUtil.join(",", Arrays.asList("animal", "monkey", "dog")));
|
||||
assertEquals("12345", StringUtil.join("", 1,2,3,4,5));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,21 +33,21 @@ import java.util.Arrays;
|
|||
* TODO: Convert to JUnit
|
||||
*/
|
||||
public class QuickSelectTest {
|
||||
public static void main(String[] args){
|
||||
int[] array = {1,3,4,6,3,2,98,5,7,8,543,2,4,5,8,9,5,2,3,5,7,5,3,2,6,8,5,324,8,6};
|
||||
//int[] array = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,17,18,19,20};
|
||||
|
||||
long time = System.currentTimeMillis();
|
||||
int median = (Integer)QuickSelect.find(new SortableIntArray(array), array.length/2);
|
||||
System.out.println("QuickSelection("+(System.currentTimeMillis()-time)+"ms): "+median);
|
||||
|
||||
time = System.currentTimeMillis();
|
||||
Arrays.sort(array);
|
||||
System.out.println("RightAnswer("+(System.currentTimeMillis()-time)+"ms): "+array[array.length/2]);
|
||||
|
||||
System.out.println("Sorted Array("+array.length+"): ");
|
||||
for(int i=0; i<array.length ;i++){
|
||||
System.out.println(array[i] +",");
|
||||
}
|
||||
}
|
||||
public static void main(String[] args){
|
||||
int[] array = {1,3,4,6,3,2,98,5,7,8,543,2,4,5,8,9,5,2,3,5,7,5,3,2,6,8,5,324,8,6};
|
||||
//int[] array = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,17,18,19,20};
|
||||
|
||||
long time = System.currentTimeMillis();
|
||||
int median = (Integer)QuickSelect.find(new SortableIntArray(array), array.length/2);
|
||||
System.out.println("QuickSelection("+(System.currentTimeMillis()-time)+"ms): "+median);
|
||||
|
||||
time = System.currentTimeMillis();
|
||||
Arrays.sort(array);
|
||||
System.out.println("RightAnswer("+(System.currentTimeMillis()-time)+"ms): "+array[array.length/2]);
|
||||
|
||||
System.out.println("Sorted Array("+array.length+"): ");
|
||||
for(int i=0; i<array.length ;i++){
|
||||
System.out.println(array[i] +",");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,15 +28,15 @@ import java.io.File;
|
|||
|
||||
|
||||
public class ExternalSortTest {
|
||||
public static void main(String[] args){
|
||||
try {
|
||||
File file = new File("C:\\Users\\Ziver\\Desktop\\IndexFile.txt");
|
||||
File sortedFile = new File("C:\\Users\\Ziver\\Desktop\\SortedIndexFile.txt");
|
||||
public static void main(String[] args){
|
||||
try {
|
||||
File file = new File("C:\\Users\\Ziver\\Desktop\\IndexFile.txt");
|
||||
File sortedFile = new File("C:\\Users\\Ziver\\Desktop\\SortedIndexFile.txt");
|
||||
|
||||
ExternalSort sort = new ExternalSort(file, sortedFile);
|
||||
sort.sort();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
ExternalSort sort = new ExternalSort(file, sortedFile);
|
||||
sort.sort();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,42 +29,42 @@ import zutil.algo.sort.sortable.SortableIntArray;
|
|||
// TODO: Convert to JUnit
|
||||
@SuppressWarnings("unused")
|
||||
public class MergeSortTest {
|
||||
public static final int SIZE = 10000;
|
||||
public static final int MAX_INT = 10000;
|
||||
public static final int SIZE = 10000;
|
||||
public static final int MAX_INT = 10000;
|
||||
|
||||
public static void main(String[] args){
|
||||
int[] array = new int[SIZE];
|
||||
|
||||
for(int i=0; i<array.length ;i++){
|
||||
array[i] = (int)(Math.random()*MAX_INT);
|
||||
}
|
||||
|
||||
for(int i=0; i<array.length ;i++){
|
||||
System.out.print(array[i]+", ");
|
||||
}
|
||||
|
||||
long time = System.currentTimeMillis();
|
||||
//SimpleSort.bubbleSort( new SortableIntArray(array) );
|
||||
//SimpleSort.selectionSort( new SortableIntArray(array) );
|
||||
//SimpleSort.insertionSort( new SortableIntArray(array) );
|
||||
//QuickSort.sort( new SortableIntArray(array) );
|
||||
//MergeSort.sort( array );
|
||||
MergeSort.sort( new SortableIntArray(array) );
|
||||
time = System.currentTimeMillis() - time;
|
||||
|
||||
System.out.println("\n--------------------------------------------");
|
||||
System.out.print(array[0]+", ");
|
||||
int error = -1;
|
||||
for(int i=1; i<array.length ;i++){
|
||||
System.out.print(array[i]+", ");
|
||||
if(array[i-1] > array[i]){
|
||||
error = i;
|
||||
}
|
||||
}
|
||||
|
||||
if(error >= 0){
|
||||
System.out.println("\nArray not sorted!! ("+array[error-1]+" > "+array[error]+")");
|
||||
}
|
||||
System.out.println("\nTime: "+time+" ms");
|
||||
}
|
||||
public static void main(String[] args){
|
||||
int[] array = new int[SIZE];
|
||||
|
||||
for(int i=0; i<array.length ;i++){
|
||||
array[i] = (int)(Math.random()*MAX_INT);
|
||||
}
|
||||
|
||||
for(int i=0; i<array.length ;i++){
|
||||
System.out.print(array[i]+", ");
|
||||
}
|
||||
|
||||
long time = System.currentTimeMillis();
|
||||
//SimpleSort.bubbleSort( new SortableIntArray(array) );
|
||||
//SimpleSort.selectionSort( new SortableIntArray(array) );
|
||||
//SimpleSort.insertionSort( new SortableIntArray(array) );
|
||||
//QuickSort.sort( new SortableIntArray(array) );
|
||||
//MergeSort.sort( array );
|
||||
MergeSort.sort( new SortableIntArray(array) );
|
||||
time = System.currentTimeMillis() - time;
|
||||
|
||||
System.out.println("\n--------------------------------------------");
|
||||
System.out.print(array[0]+", ");
|
||||
int error = -1;
|
||||
for(int i=1; i<array.length ;i++){
|
||||
System.out.print(array[i]+", ");
|
||||
if(array[i-1] > array[i]){
|
||||
error = i;
|
||||
}
|
||||
}
|
||||
|
||||
if(error >= 0){
|
||||
System.out.println("\nArray not sorted!! ("+array[error-1]+" > "+array[error]+")");
|
||||
}
|
||||
System.out.println("\nTime: "+time+" ms");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,23 +32,23 @@ import static org.junit.Assert.assertEquals;
|
|||
|
||||
public class ConverterTest {
|
||||
|
||||
@Test
|
||||
public void testHexToByte() {
|
||||
assertEquals( (byte)1, Converter.hexToByte('1') );
|
||||
assertEquals( (byte)5, Converter.hexToByte('5') );
|
||||
assertEquals( (byte)10, Converter.hexToByte('A') );
|
||||
assertEquals( (byte)10, Converter.hexToByte('a') );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHexToByte2() {
|
||||
assertEquals( 0x00, Converter.hexToByte('0','0') );
|
||||
assertEquals( 0x11, Converter.hexToByte('1','1') );
|
||||
assertEquals( 0x75, Converter.hexToByte('7','5') );
|
||||
assertEquals( 0xDA, Converter.hexToByte('D','A') & 0xFF );
|
||||
assertEquals( 0xFA, Converter.hexToByte('F','a') & 0xFF );
|
||||
assertEquals( 0xFF, Converter.hexToByte('f','f') & 0xFF );
|
||||
}
|
||||
@Test
|
||||
public void testHexToByte() {
|
||||
assertEquals( (byte)1, Converter.hexToByte('1') );
|
||||
assertEquals( (byte)5, Converter.hexToByte('5') );
|
||||
assertEquals( (byte)10, Converter.hexToByte('A') );
|
||||
assertEquals( (byte)10, Converter.hexToByte('a') );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHexToByte2() {
|
||||
assertEquals( 0x00, Converter.hexToByte('0','0') );
|
||||
assertEquals( 0x11, Converter.hexToByte('1','1') );
|
||||
assertEquals( 0x75, Converter.hexToByte('7','5') );
|
||||
assertEquals( 0xDA, Converter.hexToByte('D','A') & 0xFF );
|
||||
assertEquals( 0xFA, Converter.hexToByte('F','a') & 0xFF );
|
||||
assertEquals( 0xFF, Converter.hexToByte('f','f') & 0xFF );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHexStringToByte() {
|
||||
|
|
@ -61,42 +61,42 @@ public class ConverterTest {
|
|||
assertArrayEquals( new byte[]{(byte)0xF1,0x10}, Converter.hexToByte("F11") );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUrlEncode() {
|
||||
assertEquals( "fas8dg7%20a0d1%2313f9g8d7%200h9a%25h0",
|
||||
Converter.urlEncode("fas8dg7 a0d1#13f9g8d7 0h9a%h0") );
|
||||
assertEquals( "9i34%202y9252%25%2623%20463765(%2f%26(",
|
||||
Converter.urlEncode("9i34 2y9252%&23 463765(/&(") );
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUrlDecode() {
|
||||
assertEquals( "fas8dg7 a0d1#13f9g8d7 0h9a%h0",
|
||||
Converter.urlDecode("fas8dg7%20a0d1%2313f9g8d7%200h9a%25h0") );
|
||||
assertEquals( "9i34 2y9252%&23 463765(/&(",
|
||||
Converter.urlDecode("9i34%202y9252%25%2623%20463765(%2f%26(") );
|
||||
}
|
||||
@Test
|
||||
public void testUrlEncode() {
|
||||
assertEquals( "fas8dg7%20a0d1%2313f9g8d7%200h9a%25h0",
|
||||
Converter.urlEncode("fas8dg7 a0d1#13f9g8d7 0h9a%h0") );
|
||||
assertEquals( "9i34%202y9252%25%2623%20463765(%2f%26(",
|
||||
Converter.urlEncode("9i34 2y9252%&23 463765(/&(") );
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUrlDecode() {
|
||||
assertEquals( "fas8dg7 a0d1#13f9g8d7 0h9a%h0",
|
||||
Converter.urlDecode("fas8dg7%20a0d1%2313f9g8d7%200h9a%25h0") );
|
||||
assertEquals( "9i34 2y9252%&23 463765(/&(",
|
||||
Converter.urlDecode("9i34%202y9252%25%2623%20463765(%2f%26(") );
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void byteArrayToInt(){
|
||||
assertEquals(0, Converter.toInt(new byte[]{}));
|
||||
assertEquals(1, Converter.toInt(new byte[]{0b0000_0001}));
|
||||
assertEquals(1, Converter.toInt(new byte[]{0x01,0x00}));
|
||||
assertEquals(256, Converter.toInt(new byte[]{0x00,0x01,0x00}));
|
||||
assertEquals(-1, Converter.toInt(new byte[]{(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF}));
|
||||
assertEquals(Integer.MAX_VALUE, Converter.toInt(new byte[]{(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0x7F}));
|
||||
assertEquals(Integer.MAX_VALUE, Converter.toInt(new byte[]{(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0x7F, (byte)0xFF,(byte)0xFF}));
|
||||
}
|
||||
@Test
|
||||
public void byteArrayToInt(){
|
||||
assertEquals(0, Converter.toInt(new byte[]{}));
|
||||
assertEquals(1, Converter.toInt(new byte[]{0b0000_0001}));
|
||||
assertEquals(1, Converter.toInt(new byte[]{0x01,0x00}));
|
||||
assertEquals(256, Converter.toInt(new byte[]{0x00,0x01,0x00}));
|
||||
assertEquals(-1, Converter.toInt(new byte[]{(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF}));
|
||||
assertEquals(Integer.MAX_VALUE, Converter.toInt(new byte[]{(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0x7F}));
|
||||
assertEquals(Integer.MAX_VALUE, Converter.toInt(new byte[]{(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0x7F, (byte)0xFF,(byte)0xFF}));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void intToByteArray(){
|
||||
assertArrayEquals(new byte[]{0x00,0x00,0x00,0x00}, Converter.toBytes(0));
|
||||
assertArrayEquals(new byte[]{0x01,0x00,0x00,0x00}, Converter.toBytes(1));
|
||||
assertArrayEquals(new byte[]{0x00,0x01,0x00,0x00}, Converter.toBytes(256));
|
||||
assertArrayEquals(new byte[]{(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF}, Converter.toBytes(-1));
|
||||
assertArrayEquals(new byte[]{(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0x7F}, Converter.toBytes(Integer.MAX_VALUE));
|
||||
assertArrayEquals(new byte[]{(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x80}, Converter.toBytes(Integer.MIN_VALUE));
|
||||
}
|
||||
@Test
|
||||
public void intToByteArray(){
|
||||
assertArrayEquals(new byte[]{0x00,0x00,0x00,0x00}, Converter.toBytes(0));
|
||||
assertArrayEquals(new byte[]{0x01,0x00,0x00,0x00}, Converter.toBytes(1));
|
||||
assertArrayEquals(new byte[]{0x00,0x01,0x00,0x00}, Converter.toBytes(256));
|
||||
assertArrayEquals(new byte[]{(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF}, Converter.toBytes(-1));
|
||||
assertArrayEquals(new byte[]{(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0x7F}, Converter.toBytes(Integer.MAX_VALUE));
|
||||
assertArrayEquals(new byte[]{(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x80}, Converter.toBytes(Integer.MIN_VALUE));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,57 +39,57 @@ import static org.junit.Assert.assertThat;
|
|||
|
||||
@RunWith(Parameterized.class)
|
||||
public class NumberToWordsConverterTest {
|
||||
|
||||
@Parameters
|
||||
public static Collection<Object[]> parameters() {
|
||||
Object[][] data = new Object[][] {
|
||||
{-77, "minus seventy seven"}
|
||||
, {-2, "minus two"}
|
||||
, {1, "one"}
|
||||
, {0, "zero"}
|
||||
, {7, "seven"}
|
||||
, {11, "eleven"}
|
||||
, {12, "twelve"}
|
||||
, {17, "seventeen"}
|
||||
, {20, "twenty"}
|
||||
, {21, "twenty one"}
|
||||
, {23, "twenty three"}
|
||||
, {25, "twenty five"}
|
||||
, {30, "thirty"}
|
||||
, {34, "thirty four"}
|
||||
, {50, "fifty"}
|
||||
, {70, "seventy"}
|
||||
, {100, "one hundred"}
|
||||
, {110, "one hundred ten"}
|
||||
, {131, "one hundred thirty one"}
|
||||
, {222, "two hundred twenty two"}
|
||||
, {1000, "one thousand"}
|
||||
, {10_000, "ten thousand"}
|
||||
, {100_000, "one hundred thousand"}
|
||||
, {1000_000, "one million"}
|
||||
, {10_000_000, "ten million"}
|
||||
, {Integer.MAX_VALUE, "two billion one hundred forty seven million four hundred eighty three thousand six hundred forty seven"}
|
||||
, {Integer.MIN_VALUE, "minus two billion one hundred forty seven million four hundred eighty three thousand six hundred forty eight"}
|
||||
};
|
||||
return Arrays.asList(data);
|
||||
}
|
||||
|
||||
|
||||
private int input;
|
||||
private String expected;
|
||||
|
||||
|
||||
public NumberToWordsConverterTest(int input, String expected) {
|
||||
this.input = input;
|
||||
this.expected = expected;
|
||||
}
|
||||
@Parameters
|
||||
public static Collection<Object[]> parameters() {
|
||||
Object[][] data = new Object[][] {
|
||||
{-77, "minus seventy seven"}
|
||||
, {-2, "minus two"}
|
||||
, {1, "one"}
|
||||
, {0, "zero"}
|
||||
, {7, "seven"}
|
||||
, {11, "eleven"}
|
||||
, {12, "twelve"}
|
||||
, {17, "seventeen"}
|
||||
, {20, "twenty"}
|
||||
, {21, "twenty one"}
|
||||
, {23, "twenty three"}
|
||||
, {25, "twenty five"}
|
||||
, {30, "thirty"}
|
||||
, {34, "thirty four"}
|
||||
, {50, "fifty"}
|
||||
, {70, "seventy"}
|
||||
, {100, "one hundred"}
|
||||
, {110, "one hundred ten"}
|
||||
, {131, "one hundred thirty one"}
|
||||
, {222, "two hundred twenty two"}
|
||||
, {1000, "one thousand"}
|
||||
, {10_000, "ten thousand"}
|
||||
, {100_000, "one hundred thousand"}
|
||||
, {1000_000, "one million"}
|
||||
, {10_000_000, "ten million"}
|
||||
, {Integer.MAX_VALUE, "two billion one hundred forty seven million four hundred eighty three thousand six hundred forty seven"}
|
||||
, {Integer.MIN_VALUE, "minus two billion one hundred forty seven million four hundred eighty three thousand six hundred forty eight"}
|
||||
};
|
||||
return Arrays.asList(data);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvert() {
|
||||
assertThat(new NumberToWordsConverter().convert(input)
|
||||
, is(equalTo(expected)));
|
||||
}
|
||||
|
||||
private int input;
|
||||
private String expected;
|
||||
|
||||
|
||||
public NumberToWordsConverterTest(int input, String expected) {
|
||||
this.input = input;
|
||||
this.expected = expected;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvert() {
|
||||
assertThat(new NumberToWordsConverter().convert(input)
|
||||
, is(equalTo(expected)));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -31,31 +31,31 @@ import java.sql.PreparedStatement;
|
|||
|
||||
public class DBConnectionTest {
|
||||
|
||||
public static void main(String[] args){
|
||||
try {
|
||||
DBConnection db = new DBConnection("koc.se","db","user","password");
|
||||
|
||||
// Query 1
|
||||
PreparedStatement sql = db.getPreparedStatement("SELECT ?");
|
||||
sql.setInt(1, 1);
|
||||
DBConnection.exec(sql);
|
||||
|
||||
// Query 2
|
||||
db.exec("UPDATE ...");
|
||||
|
||||
// Query 3
|
||||
String s = db.exec("SELECT hello", new SimpleSQLResult<String>());
|
||||
System.out.println( s );
|
||||
|
||||
// Query 4
|
||||
PreparedStatement sql2 = db.getPreparedStatement("SELECT ?");
|
||||
sql2.setString(1, "hello");
|
||||
String s2 = DBConnection.exec(sql2, new SimpleSQLResult<String>());
|
||||
System.out.println( s2 );
|
||||
|
||||
db.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
public static void main(String[] args){
|
||||
try {
|
||||
DBConnection db = new DBConnection("koc.se","db","user","password");
|
||||
|
||||
// Query 1
|
||||
PreparedStatement sql = db.getPreparedStatement("SELECT ?");
|
||||
sql.setInt(1, 1);
|
||||
DBConnection.exec(sql);
|
||||
|
||||
// Query 2
|
||||
db.exec("UPDATE ...");
|
||||
|
||||
// Query 3
|
||||
String s = db.exec("SELECT hello", new SimpleSQLResult<String>());
|
||||
System.out.println( s );
|
||||
|
||||
// Query 4
|
||||
PreparedStatement sql2 = db.getPreparedStatement("SELECT ?");
|
||||
sql2.setString(1, "hello");
|
||||
String s2 = DBConnection.exec(sql2, new SimpleSQLResult<String>());
|
||||
System.out.println( s2 );
|
||||
|
||||
db.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,90 +31,90 @@ import static org.junit.Assert.assertEquals;
|
|||
|
||||
public class SQLQueryTest {
|
||||
|
||||
@Test
|
||||
public void selectTest() {
|
||||
assertEquals( "SELECT * FROM test1",
|
||||
""+SQLQuery.SELECT().FROM("test1") );
|
||||
assertEquals( "SELECT * FROM test1",
|
||||
""+SQLQuery.SELECT("*").FROM("test1") );
|
||||
assertEquals( "SELECT test1,test2 FROM test1",
|
||||
""+SQLQuery.SELECT("test1","test2").FROM("test1") );
|
||||
}
|
||||
@Test
|
||||
public void selectJoinTest() {
|
||||
assertEquals( "SELECT * FROM test1 JOIN test2",
|
||||
""+SQLQuery.SELECT("*").FROM("test1").JOIN("test2") );
|
||||
assertEquals( "SELECT * FROM test1 NATURAL JOIN test2",
|
||||
""+SQLQuery.SELECT("*").FROM("test1").NATURAL_JOIN("test2") );
|
||||
assertEquals( "SELECT * FROM test1 UNION test2",
|
||||
""+SQLQuery.SELECT("*").FROM("test1").UNION("test2") );
|
||||
assertEquals( "SELECT * FROM test1 JOIN test2 NATURAL JOIN test3 UNION test4",
|
||||
""+SQLQuery.SELECT("*").FROM("test1").JOIN("test2").NATURAL_JOIN("test3").UNION("test4") );
|
||||
|
||||
assertEquals( "SELECT * FROM test1 NATURAL JOIN test2 NATURAL JOIN test3 NATURAL JOIN test4",
|
||||
""+SQLQuery.SELECT("*").FROM().NATURAL_JOIN("test1","test2","test3","test4") );
|
||||
assertEquals( "SELECT * FROM test1 JOIN test2 JOIN test3 JOIN test4",
|
||||
""+SQLQuery.SELECT("*").FROM().JOIN("test1","test2","test3","test4") );
|
||||
assertEquals( "SELECT * FROM test1 UNION test2 UNION test3 UNION test4",
|
||||
""+SQLQuery.SELECT("*").FROM().UNION("test1","test2","test3","test4") );
|
||||
}
|
||||
@Test
|
||||
public void selectWhereTest() {
|
||||
assertEquals( "SELECT * FROM test1 WHERE arg=value",
|
||||
""+SQLQuery.SELECT("*").FROM("test1").WHERE().EQ("arg","value") );
|
||||
}
|
||||
@Test
|
||||
public void selectGroupByTest() {
|
||||
assertEquals( "SELECT * FROM test1 GROUP BY col1",
|
||||
""+SQLQuery.SELECT("*").FROM("test1").GROUP_BY("col1") );
|
||||
assertEquals( "SELECT * FROM test1 WHERE arg=value GROUP BY col1",
|
||||
""+SQLQuery.SELECT("*").FROM("test1").WHERE().EQ("arg","value").GROUP_BY("col1") );
|
||||
assertEquals( "SELECT * FROM test1 WHERE arg=value GROUP BY col1 ASC",
|
||||
""+SQLQuery.SELECT("*").FROM("test1").WHERE().EQ("arg","value").GROUP_BY("col1").ASC() );
|
||||
assertEquals( "SELECT * FROM test1 WHERE arg=value GROUP BY col1 DESC",
|
||||
""+SQLQuery.SELECT("*").FROM("test1").WHERE().EQ("arg","value").GROUP_BY("col1").DESC() );
|
||||
}
|
||||
@Test
|
||||
public void selectOrderByTest() {
|
||||
assertEquals( "SELECT * FROM test1 WHERE arg=value ORDER BY col1",
|
||||
""+SQLQuery.SELECT("*").FROM("test1").WHERE().EQ("arg","value").ORDER_BY("col1") );
|
||||
assertEquals( "SELECT * FROM test1 WHERE arg=value ORDER BY col1 ASC",
|
||||
""+SQLQuery.SELECT("*").FROM("test1").WHERE().EQ("arg","value").ORDER_BY("col1").ASC() );
|
||||
assertEquals( "SELECT * FROM test1 WHERE arg=value ORDER BY col1 DESC",
|
||||
""+SQLQuery.SELECT("*").FROM("test1").WHERE().EQ("arg","value").ORDER_BY("col1").DESC() );
|
||||
assertEquals( "SELECT * FROM test1 WHERE arg=value GROUP BY col1 ORDER BY col2 DESC",
|
||||
""+SQLQuery.SELECT("*").FROM("test1").WHERE().EQ("arg","value").GROUP_BY("col1").ORDER_BY("col2").DESC() );
|
||||
assertEquals( "SELECT * FROM test1 WHERE arg=value GROUP BY col1 ASC ORDER BY col2 DESC",
|
||||
""+SQLQuery.SELECT("*").FROM("test1").WHERE().EQ("arg","value").GROUP_BY("col1").ASC().ORDER_BY("col2").DESC() );
|
||||
}
|
||||
@Test
|
||||
public void selectLimitTest() {
|
||||
assertEquals( "SELECT * FROM test1 LIMIT 1",
|
||||
""+SQLQuery.SELECT("*").FROM("test1").LIMIT(1) );
|
||||
assertEquals( "SELECT * FROM test1 LIMIT 1 4",
|
||||
""+SQLQuery.SELECT("*").FROM("test1").LIMIT(1).TO(4) );
|
||||
assertEquals( "SELECT * FROM test1 WHERE arg=value LIMIT 1",
|
||||
""+SQLQuery.SELECT("*").FROM("test1").WHERE().EQ("arg","value").LIMIT(1) );
|
||||
assertEquals( "SELECT * FROM test1 WHERE arg=value ORDER BY col1 DESC LIMIT 1",
|
||||
""+SQLQuery.SELECT("*").FROM("test1").WHERE().EQ("arg","value").ORDER_BY("col1").DESC().LIMIT(1) );
|
||||
assertEquals( "SELECT * FROM test1 WHERE arg=value GROUP BY col1 ORDER BY col2 DESC LIMIT 1",
|
||||
""+SQLQuery.SELECT("*").FROM("test1").WHERE().EQ("arg","value").GROUP_BY("col1").ORDER_BY("col2").DESC().LIMIT(1) );
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void updateTest() {
|
||||
|
||||
}
|
||||
@Test
|
||||
public void selectTest() {
|
||||
assertEquals( "SELECT * FROM test1",
|
||||
""+SQLQuery.SELECT().FROM("test1") );
|
||||
assertEquals( "SELECT * FROM test1",
|
||||
""+SQLQuery.SELECT("*").FROM("test1") );
|
||||
assertEquals( "SELECT test1,test2 FROM test1",
|
||||
""+SQLQuery.SELECT("test1","test2").FROM("test1") );
|
||||
}
|
||||
@Test
|
||||
public void selectJoinTest() {
|
||||
assertEquals( "SELECT * FROM test1 JOIN test2",
|
||||
""+SQLQuery.SELECT("*").FROM("test1").JOIN("test2") );
|
||||
assertEquals( "SELECT * FROM test1 NATURAL JOIN test2",
|
||||
""+SQLQuery.SELECT("*").FROM("test1").NATURAL_JOIN("test2") );
|
||||
assertEquals( "SELECT * FROM test1 UNION test2",
|
||||
""+SQLQuery.SELECT("*").FROM("test1").UNION("test2") );
|
||||
assertEquals( "SELECT * FROM test1 JOIN test2 NATURAL JOIN test3 UNION test4",
|
||||
""+SQLQuery.SELECT("*").FROM("test1").JOIN("test2").NATURAL_JOIN("test3").UNION("test4") );
|
||||
|
||||
|
||||
@Test
|
||||
public void deleteTest() {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createTest() {
|
||||
|
||||
}
|
||||
assertEquals( "SELECT * FROM test1 NATURAL JOIN test2 NATURAL JOIN test3 NATURAL JOIN test4",
|
||||
""+SQLQuery.SELECT("*").FROM().NATURAL_JOIN("test1","test2","test3","test4") );
|
||||
assertEquals( "SELECT * FROM test1 JOIN test2 JOIN test3 JOIN test4",
|
||||
""+SQLQuery.SELECT("*").FROM().JOIN("test1","test2","test3","test4") );
|
||||
assertEquals( "SELECT * FROM test1 UNION test2 UNION test3 UNION test4",
|
||||
""+SQLQuery.SELECT("*").FROM().UNION("test1","test2","test3","test4") );
|
||||
}
|
||||
@Test
|
||||
public void selectWhereTest() {
|
||||
assertEquals( "SELECT * FROM test1 WHERE arg=value",
|
||||
""+SQLQuery.SELECT("*").FROM("test1").WHERE().EQ("arg","value") );
|
||||
}
|
||||
@Test
|
||||
public void selectGroupByTest() {
|
||||
assertEquals( "SELECT * FROM test1 GROUP BY col1",
|
||||
""+SQLQuery.SELECT("*").FROM("test1").GROUP_BY("col1") );
|
||||
assertEquals( "SELECT * FROM test1 WHERE arg=value GROUP BY col1",
|
||||
""+SQLQuery.SELECT("*").FROM("test1").WHERE().EQ("arg","value").GROUP_BY("col1") );
|
||||
assertEquals( "SELECT * FROM test1 WHERE arg=value GROUP BY col1 ASC",
|
||||
""+SQLQuery.SELECT("*").FROM("test1").WHERE().EQ("arg","value").GROUP_BY("col1").ASC() );
|
||||
assertEquals( "SELECT * FROM test1 WHERE arg=value GROUP BY col1 DESC",
|
||||
""+SQLQuery.SELECT("*").FROM("test1").WHERE().EQ("arg","value").GROUP_BY("col1").DESC() );
|
||||
}
|
||||
@Test
|
||||
public void selectOrderByTest() {
|
||||
assertEquals( "SELECT * FROM test1 WHERE arg=value ORDER BY col1",
|
||||
""+SQLQuery.SELECT("*").FROM("test1").WHERE().EQ("arg","value").ORDER_BY("col1") );
|
||||
assertEquals( "SELECT * FROM test1 WHERE arg=value ORDER BY col1 ASC",
|
||||
""+SQLQuery.SELECT("*").FROM("test1").WHERE().EQ("arg","value").ORDER_BY("col1").ASC() );
|
||||
assertEquals( "SELECT * FROM test1 WHERE arg=value ORDER BY col1 DESC",
|
||||
""+SQLQuery.SELECT("*").FROM("test1").WHERE().EQ("arg","value").ORDER_BY("col1").DESC() );
|
||||
assertEquals( "SELECT * FROM test1 WHERE arg=value GROUP BY col1 ORDER BY col2 DESC",
|
||||
""+SQLQuery.SELECT("*").FROM("test1").WHERE().EQ("arg","value").GROUP_BY("col1").ORDER_BY("col2").DESC() );
|
||||
assertEquals( "SELECT * FROM test1 WHERE arg=value GROUP BY col1 ASC ORDER BY col2 DESC",
|
||||
""+SQLQuery.SELECT("*").FROM("test1").WHERE().EQ("arg","value").GROUP_BY("col1").ASC().ORDER_BY("col2").DESC() );
|
||||
}
|
||||
@Test
|
||||
public void selectLimitTest() {
|
||||
assertEquals( "SELECT * FROM test1 LIMIT 1",
|
||||
""+SQLQuery.SELECT("*").FROM("test1").LIMIT(1) );
|
||||
assertEquals( "SELECT * FROM test1 LIMIT 1 4",
|
||||
""+SQLQuery.SELECT("*").FROM("test1").LIMIT(1).TO(4) );
|
||||
assertEquals( "SELECT * FROM test1 WHERE arg=value LIMIT 1",
|
||||
""+SQLQuery.SELECT("*").FROM("test1").WHERE().EQ("arg","value").LIMIT(1) );
|
||||
assertEquals( "SELECT * FROM test1 WHERE arg=value ORDER BY col1 DESC LIMIT 1",
|
||||
""+SQLQuery.SELECT("*").FROM("test1").WHERE().EQ("arg","value").ORDER_BY("col1").DESC().LIMIT(1) );
|
||||
assertEquals( "SELECT * FROM test1 WHERE arg=value GROUP BY col1 ORDER BY col2 DESC LIMIT 1",
|
||||
""+SQLQuery.SELECT("*").FROM("test1").WHERE().EQ("arg","value").GROUP_BY("col1").ORDER_BY("col2").DESC().LIMIT(1) );
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void updateTest() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void deleteTest() {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createTest() {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,90 +41,90 @@ import java.io.InputStream;
|
|||
|
||||
@SuppressWarnings({ "unused", "rawtypes" })
|
||||
public class ImageProcessorTest implements ProgressListener{
|
||||
private static String imgPath = "test.gif";
|
||||
//private static String imgPath = "test2.jpg";
|
||||
private static String imgPath = "test.gif";
|
||||
//private static String imgPath = "test2.jpg";
|
||||
|
||||
private JLabel processedLabel;
|
||||
private JLabel orginalLabel;
|
||||
private JProgressBar progress;
|
||||
private JLabel processedLabel;
|
||||
private JLabel orginalLabel;
|
||||
private JProgressBar progress;
|
||||
|
||||
public static void main(String[] args){
|
||||
new ImageProcessorTest();
|
||||
}
|
||||
public static void main(String[] args){
|
||||
new ImageProcessorTest();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public ImageProcessorTest(){
|
||||
JFrame frame = getJFrame();
|
||||
BufferedImage img = null;
|
||||
@SuppressWarnings("unchecked")
|
||||
public ImageProcessorTest(){
|
||||
JFrame frame = getJFrame();
|
||||
BufferedImage img = null;
|
||||
|
||||
try {
|
||||
// Read from an input stream
|
||||
InputStream is = new BufferedInputStream(new FileInputStream(imgPath));
|
||||
img = ImageIO.read(is);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
System.exit(1);
|
||||
}
|
||||
try {
|
||||
// Read from an input stream
|
||||
InputStream is = new BufferedInputStream(new FileInputStream(imgPath));
|
||||
img = ImageIO.read(is);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
ImageIcon orginalIcon = new ImageIcon(img);
|
||||
orginalLabel.setIcon(orginalIcon);
|
||||
frame.setVisible(true);
|
||||
frame.pack();
|
||||
|
||||
BufferedImage procImg = null;
|
||||
try {
|
||||
//ImageFilterProcessor processor = new SobelEdgeDetectionFilter(img);
|
||||
ImageFilterProcessor processor = new GaussianBlurFilter(img);
|
||||
//ImageFilterProcessor processor = new BlurFilter(img, 100);
|
||||
//ImageFilterProcessor processor = new ColorIntensityFilter(img, true);
|
||||
//ImageFilterProcessor processor = new ContrastBrightnessFilter(img);
|
||||
//ImageFilterProcessor processor = new DitheringFilter(img);
|
||||
//ImageFilterProcessor processor = new MeanBlurFilter(img);
|
||||
//ImageFilterProcessor processor = new MedianFilter(img);
|
||||
//ImageFilterProcessor processor = new ResizeImage(img,100,100);
|
||||
//ImageFilterProcessor processor = new SpotLightFilter(img,100,100,100);
|
||||
|
||||
processor.setProgressListener(this);
|
||||
procImg = processor.process();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
ImageIcon processedIcon = new ImageIcon(procImg);
|
||||
processedLabel.setIcon(processedIcon);
|
||||
ImageIcon orginalIcon = new ImageIcon(img);
|
||||
orginalLabel.setIcon(orginalIcon);
|
||||
frame.setVisible(true);
|
||||
frame.pack();
|
||||
|
||||
|
||||
frame.pack();
|
||||
}
|
||||
BufferedImage procImg = null;
|
||||
try {
|
||||
//ImageFilterProcessor processor = new SobelEdgeDetectionFilter(img);
|
||||
ImageFilterProcessor processor = new GaussianBlurFilter(img);
|
||||
//ImageFilterProcessor processor = new BlurFilter(img, 100);
|
||||
//ImageFilterProcessor processor = new ColorIntensityFilter(img, true);
|
||||
//ImageFilterProcessor processor = new ContrastBrightnessFilter(img);
|
||||
//ImageFilterProcessor processor = new DitheringFilter(img);
|
||||
//ImageFilterProcessor processor = new MeanBlurFilter(img);
|
||||
//ImageFilterProcessor processor = new MedianFilter(img);
|
||||
//ImageFilterProcessor processor = new ResizeImage(img,100,100);
|
||||
//ImageFilterProcessor processor = new SpotLightFilter(img,100,100,100);
|
||||
|
||||
private JFrame getJFrame() {
|
||||
processedLabel = new JLabel("Processed");
|
||||
orginalLabel = new JLabel("Orginal");
|
||||
|
||||
progress = new JProgressBar();
|
||||
progress.setMaximum(100);
|
||||
progress.setValue(0);
|
||||
progress.setIndeterminate(false);
|
||||
progress.setStringPainted(true);
|
||||
|
||||
JPanel jPanel = new JPanel();
|
||||
jPanel.setLayout(new BorderLayout());
|
||||
jPanel.add(orginalLabel, BorderLayout.NORTH);
|
||||
jPanel.add(processedLabel, BorderLayout.CENTER);
|
||||
jPanel.add(progress, BorderLayout.SOUTH);
|
||||
processor.setProgressListener(this);
|
||||
procImg = processor.process();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
ImageIcon processedIcon = new ImageIcon(procImg);
|
||||
processedLabel.setIcon(processedIcon);
|
||||
|
||||
JFrame jFrame = new JFrame("ImageProcessorTest");
|
||||
jFrame.setSize(new Dimension(715, 361));
|
||||
jFrame.setContentPane(jPanel);
|
||||
jFrame.addWindowListener(new WindowAdapter() {
|
||||
public void windowClosing(WindowEvent e) {
|
||||
System.exit(0);
|
||||
}
|
||||
});
|
||||
|
||||
return jFrame;
|
||||
}
|
||||
frame.pack();
|
||||
}
|
||||
|
||||
public void progressUpdate(Object source, Object info, double percent) {
|
||||
progress.setValue((int)percent);
|
||||
}
|
||||
private JFrame getJFrame() {
|
||||
processedLabel = new JLabel("Processed");
|
||||
orginalLabel = new JLabel("Orginal");
|
||||
|
||||
progress = new JProgressBar();
|
||||
progress.setMaximum(100);
|
||||
progress.setValue(0);
|
||||
progress.setIndeterminate(false);
|
||||
progress.setStringPainted(true);
|
||||
|
||||
JPanel jPanel = new JPanel();
|
||||
jPanel.setLayout(new BorderLayout());
|
||||
jPanel.add(orginalLabel, BorderLayout.NORTH);
|
||||
jPanel.add(processedLabel, BorderLayout.CENTER);
|
||||
jPanel.add(progress, BorderLayout.SOUTH);
|
||||
|
||||
JFrame jFrame = new JFrame("ImageProcessorTest");
|
||||
jFrame.setSize(new Dimension(715, 361));
|
||||
jFrame.setContentPane(jPanel);
|
||||
jFrame.addWindowListener(new WindowAdapter() {
|
||||
public void windowClosing(WindowEvent e) {
|
||||
System.exit(0);
|
||||
}
|
||||
});
|
||||
|
||||
return jFrame;
|
||||
}
|
||||
|
||||
public void progressUpdate(Object source, Object info, double percent) {
|
||||
progress.setValue((int)percent);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -58,18 +58,18 @@ public class BufferedBoundaryInputStreamTest {
|
|||
|
||||
|
||||
|
||||
@Test
|
||||
public void read_normal() throws IOException {
|
||||
@Test
|
||||
public void read_normal() throws IOException {
|
||||
BufferedBoundaryInputStream in = getBufferedBoundaryInputStream("aaa#a##aaaaaaa#", "#");
|
||||
|
||||
assertTrue(in.hasNext());
|
||||
assertTrue(in.hasNext());
|
||||
assertEquals('a', in.read());
|
||||
assertEquals('a', in.read());
|
||||
assertEquals('a', in.read());
|
||||
assertEquals(-1, in.read());
|
||||
|
||||
assertTrue(in.hasNext());
|
||||
in.next();
|
||||
in.next();
|
||||
assertEquals('a', in.read());
|
||||
assertEquals(-1, in.read());
|
||||
|
||||
|
|
@ -89,33 +89,33 @@ public class BufferedBoundaryInputStreamTest {
|
|||
assertEquals(-1, in.read());
|
||||
|
||||
assertFalse(in.hasNext());
|
||||
in.next();
|
||||
assertEquals(-1, in.read());
|
||||
in.next();
|
||||
assertEquals(-1, in.read());
|
||||
assertFalse(in.hasNext());
|
||||
}
|
||||
}
|
||||
@Test
|
||||
public void readArr_normal() throws IOException {
|
||||
public void readArr_normal() throws IOException {
|
||||
BufferedBoundaryInputStream in = getBufferedBoundaryInputStream("aaa#aaaaaaaaaaaaaaaa#aaaaaaaaaaaaaaa#", "#");
|
||||
|
||||
byte[] buff = new byte[100];
|
||||
int n = in.read(buff);
|
||||
assertEquals(3, n);
|
||||
byte[] buff = new byte[100];
|
||||
int n = in.read(buff);
|
||||
assertEquals(3, n);
|
||||
|
||||
assertTrue(in.hasNext());
|
||||
in.next();
|
||||
n = in.read(buff);
|
||||
assertEquals(16, n);
|
||||
assertTrue(in.hasNext());
|
||||
in.next();
|
||||
n = in.read(buff);
|
||||
assertEquals(16, n);
|
||||
|
||||
assertTrue(in.hasNext());
|
||||
in.next();
|
||||
n = in.read(buff);
|
||||
assertEquals(15, n);
|
||||
assertTrue(in.hasNext());
|
||||
in.next();
|
||||
n = in.read(buff);
|
||||
assertEquals(15, n);
|
||||
|
||||
assertFalse(in.hasNext());
|
||||
in.next();
|
||||
n = in.read(buff);
|
||||
assertEquals(-1, n);
|
||||
}
|
||||
assertFalse(in.hasNext());
|
||||
in.next();
|
||||
n = in.read(buff);
|
||||
assertEquals(-1, n);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void read_multiCharBoundary() throws IOException {
|
||||
|
|
@ -151,57 +151,57 @@ public class BufferedBoundaryInputStreamTest {
|
|||
assertFalse(in.hasNext());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void read_startWithBound() throws IOException {
|
||||
@Test
|
||||
public void read_startWithBound() throws IOException {
|
||||
BufferedBoundaryInputStream in = getBufferedBoundaryInputStream("#aaa", "#");
|
||||
|
||||
assertEquals(-1, in.read());
|
||||
}
|
||||
@Test
|
||||
public void readArr_startWithBound() throws IOException {
|
||||
assertEquals(-1, in.read());
|
||||
}
|
||||
@Test
|
||||
public void readArr_startWithBound() throws IOException {
|
||||
BufferedBoundaryInputStream in = getBufferedBoundaryInputStream("#aaa", "#");
|
||||
|
||||
assertEquals(-1, in.read(new byte[10], 0, 10));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void read_onlyBoundaries() throws IOException {
|
||||
@Test
|
||||
public void read_onlyBoundaries() throws IOException {
|
||||
BufferedBoundaryInputStream in = getBufferedBoundaryInputStream("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "a");
|
||||
|
||||
int n;
|
||||
for(n=1; in.hasNext(); n++){
|
||||
assertEquals(-1, in.read());
|
||||
assertEquals(-1, in.read());
|
||||
in.next();
|
||||
}
|
||||
assertEquals(35, n);
|
||||
}
|
||||
@Test
|
||||
public void readArr_onlyBoundaries() throws IOException {
|
||||
|
||||
int n;
|
||||
for(n=1; in.hasNext(); n++){
|
||||
assertEquals(-1, in.read());
|
||||
assertEquals(-1, in.read());
|
||||
in.next();
|
||||
}
|
||||
assertEquals(35, n);
|
||||
}
|
||||
@Test
|
||||
public void readArr_onlyBoundaries() throws IOException {
|
||||
BufferedBoundaryInputStream in = getBufferedBoundaryInputStream("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "a");
|
||||
|
||||
byte[] buff = new byte[100];
|
||||
int n;
|
||||
for(n=1; in.hasNext(); n++){
|
||||
assertEquals(-1, in.read(buff));
|
||||
assertEquals(-1, in.read(buff));
|
||||
in.next();
|
||||
}
|
||||
assertEquals(35, n);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void read_noBounds() throws IOException {
|
||||
String data = "1234567891011121314151617181920";
|
||||
int n;
|
||||
for(n=1; in.hasNext(); n++){
|
||||
assertEquals(-1, in.read(buff));
|
||||
assertEquals(-1, in.read(buff));
|
||||
in.next();
|
||||
}
|
||||
assertEquals(35, n);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void read_noBounds() throws IOException {
|
||||
String data = "1234567891011121314151617181920";
|
||||
BufferedBoundaryInputStream in = getBufferedBoundaryInputStream(data, "#");
|
||||
|
||||
int out;
|
||||
StringBuilder output = new StringBuilder();
|
||||
while((out = in.read()) != -1){
|
||||
output.append((char)out);
|
||||
}
|
||||
assertEquals(data, output.toString());
|
||||
}
|
||||
|
||||
int out;
|
||||
StringBuilder output = new StringBuilder();
|
||||
while((out = in.read()) != -1){
|
||||
output.append((char)out);
|
||||
}
|
||||
assertEquals(data, output.toString());
|
||||
}
|
||||
@Test
|
||||
public void readArr_noBounds() throws IOException {
|
||||
String data = "1234567891011121314151617181920";
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ public class DynamicByteArrayStreamTest {
|
|||
|
||||
byte[] result = out.getBytes();
|
||||
for(int i=0; i<b.length; i++){
|
||||
assertEquals(b[i], result[i]);
|
||||
assertEquals(b[i], result[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,21 +30,21 @@ import java.net.URISyntaxException;
|
|||
|
||||
|
||||
public class FileChangedTest implements FileChangeListener{
|
||||
public static void main(String[] args) throws URISyntaxException, FileNotFoundException{
|
||||
FileWatcher watcher = new FileWatcher(FileUtil.find("test.txt"));
|
||||
watcher.setListener(new FileChangedTest());
|
||||
|
||||
while(true){
|
||||
try {
|
||||
Thread.sleep(10);
|
||||
} catch (InterruptedException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
public static void main(String[] args) throws URISyntaxException, FileNotFoundException{
|
||||
FileWatcher watcher = new FileWatcher(FileUtil.find("test.txt"));
|
||||
watcher.setListener(new FileChangedTest());
|
||||
|
||||
public void fileChangedEvent(File file) {
|
||||
System.out.println(file);
|
||||
}
|
||||
while(true){
|
||||
try {
|
||||
Thread.sleep(10);
|
||||
} catch (InterruptedException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void fileChangedEvent(File file) {
|
||||
System.out.println(file);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,50 +24,50 @@
|
|||
|
||||
<html>
|
||||
<head>
|
||||
<script type='text/javascript' src='js/jquery-1.4.2.min.js'></script>
|
||||
<script type='text/javascript' src='upload?js'></script>
|
||||
<style type='text/css'>
|
||||
.progressbar{
|
||||
background: transparent url(img/bar-grey.gif) repeat-x scroll 0%;
|
||||
border: 1px solid black;
|
||||
color: white;
|
||||
height: 16px;
|
||||
margin: 0pt;
|
||||
padding: 0pt;
|
||||
position: relative;
|
||||
text-align: center;
|
||||
width; 150px;
|
||||
border-collapse: collapse;
|
||||
}
|
||||
.progressbar b{
|
||||
background: transparent url(img/bar-revered.gif) repeat-x scroll 0%;
|
||||
float: left;
|
||||
height: 16px;
|
||||
margin: 0pt;
|
||||
padding: 0pt;
|
||||
font-size: 11px;
|
||||
}
|
||||
|
||||
ul{
|
||||
list-style-type: none;
|
||||
padding: 0px;
|
||||
margin: 0px;
|
||||
}
|
||||
</style>
|
||||
<script type='text/javascript' src='js/jquery-1.4.2.min.js'></script>
|
||||
<script type='text/javascript' src='upload?js'></script>
|
||||
<style type='text/css'>
|
||||
.progressbar{
|
||||
background: transparent url(img/bar-grey.gif) repeat-x scroll 0%;
|
||||
border: 1px solid black;
|
||||
color: white;
|
||||
height: 16px;
|
||||
margin: 0pt;
|
||||
padding: 0pt;
|
||||
position: relative;
|
||||
text-align: center;
|
||||
width; 150px;
|
||||
border-collapse: collapse;
|
||||
}
|
||||
.progressbar b{
|
||||
background: transparent url(img/bar-revered.gif) repeat-x scroll 0%;
|
||||
float: left;
|
||||
height: 16px;
|
||||
margin: 0pt;
|
||||
padding: 0pt;
|
||||
font-size: 11px;
|
||||
}
|
||||
|
||||
ul{
|
||||
list-style-type: none;
|
||||
padding: 0px;
|
||||
margin: 0px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<FORM id="AjaxFileUpload">
|
||||
<INPUT type="file" name="file" multiple/>
|
||||
<INPUT type="submit" />
|
||||
</FORM>
|
||||
<UL id="UploadQueue">
|
||||
<li id="1367232194">
|
||||
<div class="progressbar">
|
||||
<b id="progress" style="width: 70%; display: block; ">
|
||||
<span id="filename">Test</span>
|
||||
</b>
|
||||
</div>
|
||||
</li>
|
||||
</UL>
|
||||
<form id="AjaxFileUpload">
|
||||
<input type="file" name="file" multiple/>
|
||||
<input type="submit" />
|
||||
</form>
|
||||
<ul id="UploadQueue">
|
||||
<li id="1367232194">
|
||||
<div class="progressbar">
|
||||
<b id="progress" style="width: 70%; display: block; ">
|
||||
<span id="filename">Test</span>
|
||||
</b>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -31,23 +31,23 @@ import java.util.logging.Logger;
|
|||
|
||||
|
||||
public class NetLogServerTest {
|
||||
private static final Logger logger = LogUtil.getLogger();
|
||||
private static final Logger logger = LogUtil.getLogger();
|
||||
|
||||
public static void main(String[] args){
|
||||
LogUtil.setGlobalLevel(Level.FINEST);
|
||||
LogUtil.addGlobalHandler(new NetLogServer(5050));
|
||||
|
||||
while(true){
|
||||
logger.log(Level.SEVERE, "Test Severe");
|
||||
logger.log(Level.WARNING, "Test Warning");
|
||||
logger.log(Level.INFO, "Test Info");
|
||||
logger.log(Level.FINE, "Test Fine");
|
||||
logger.log(Level.FINER, "Test Finer");
|
||||
logger.log(Level.FINEST, "Test Finest");
|
||||
|
||||
logger.log(Level.SEVERE, "Test Exception", new Exception("Test"));
|
||||
|
||||
try{Thread.sleep(3000);}catch(Exception e){}
|
||||
}
|
||||
}
|
||||
public static void main(String[] args){
|
||||
LogUtil.setGlobalLevel(Level.FINEST);
|
||||
LogUtil.addGlobalHandler(new NetLogServer(5050));
|
||||
|
||||
while(true){
|
||||
logger.log(Level.SEVERE, "Test Severe");
|
||||
logger.log(Level.WARNING, "Test Warning");
|
||||
logger.log(Level.INFO, "Test Info");
|
||||
logger.log(Level.FINE, "Test Fine");
|
||||
logger.log(Level.FINER, "Test Finer");
|
||||
logger.log(Level.FINEST, "Test Finest");
|
||||
|
||||
logger.log(Level.SEVERE, "Test Exception", new Exception("Test"));
|
||||
|
||||
try{Thread.sleep(3000);}catch(Exception e){}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,12 +28,12 @@ import java.io.IOException;
|
|||
|
||||
|
||||
public class ServerFindClientTest {
|
||||
public static void main(String[] args){
|
||||
try {
|
||||
ServerFindClient client = new ServerFindClient(2000);
|
||||
System.out.println(client.find().getHostAddress());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
public static void main(String[] args){
|
||||
try {
|
||||
ServerFindClient client = new ServerFindClient(2000);
|
||||
System.out.println(client.find().getHostAddress());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,11 +28,11 @@ import java.io.IOException;
|
|||
|
||||
|
||||
public class ServerFindServerTest {
|
||||
public static void main(String[] args){
|
||||
try {
|
||||
new ServerFind(2000);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
public static void main(String[] args){
|
||||
try {
|
||||
new ServerFind(2000);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,41 +34,41 @@ import static org.junit.Assert.assertEquals;
|
|||
|
||||
public class HttpURLTest {
|
||||
|
||||
@Test
|
||||
public void fullURLTest() {
|
||||
HttpURL url = new HttpURL();
|
||||
url.setProtocol("http");
|
||||
assertEquals( "http://127.0.0.1/", url.getURL() );
|
||||
|
||||
url.setHost("koc.se");
|
||||
assertEquals( "http://koc.se/", url.getURL() );
|
||||
|
||||
url.setPort( 80 );
|
||||
assertEquals( "http://koc.se:80/", url.getURL() );
|
||||
|
||||
url.setPath("test/index.html");
|
||||
assertEquals( "http://koc.se:80/test/index.html", url.getURL() );
|
||||
|
||||
url.setParameter("key", "value");
|
||||
assertEquals( "http://koc.se:80/test/index.html?key=value", url.getURL() );
|
||||
|
||||
url.setAnchor( "anch" );
|
||||
assertEquals( "http://koc.se:80/test/index.html?key=value#anch", url.getURL() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void urlParameterTest() {
|
||||
HttpURL url = new HttpURL();
|
||||
url.setParameter("key1", "value1");
|
||||
assertEquals( "key1=value1", url.getParameterString() );
|
||||
|
||||
url.setParameter("key1", "value1");
|
||||
assertEquals( "key1=value1", url.getParameterString() );
|
||||
|
||||
url.setParameter("key2", "value2");
|
||||
assertThat(url.getParameterString(), allOf(containsString("key2=value2"), containsString("key1=value1")));
|
||||
@Test
|
||||
public void fullURLTest() {
|
||||
HttpURL url = new HttpURL();
|
||||
url.setProtocol("http");
|
||||
assertEquals( "http://127.0.0.1/", url.getURL() );
|
||||
|
||||
}
|
||||
url.setHost("koc.se");
|
||||
assertEquals( "http://koc.se/", url.getURL() );
|
||||
|
||||
url.setPort( 80 );
|
||||
assertEquals( "http://koc.se:80/", url.getURL() );
|
||||
|
||||
url.setPath("test/index.html");
|
||||
assertEquals( "http://koc.se:80/test/index.html", url.getURL() );
|
||||
|
||||
url.setParameter("key", "value");
|
||||
assertEquals( "http://koc.se:80/test/index.html?key=value", url.getURL() );
|
||||
|
||||
url.setAnchor( "anch" );
|
||||
assertEquals( "http://koc.se:80/test/index.html?key=value#anch", url.getURL() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void urlParameterTest() {
|
||||
HttpURL url = new HttpURL();
|
||||
url.setParameter("key1", "value1");
|
||||
assertEquals( "key1=value1", url.getParameterString() );
|
||||
|
||||
url.setParameter("key1", "value1");
|
||||
assertEquals( "key1=value1", url.getParameterString() );
|
||||
|
||||
url.setParameter("key2", "value2");
|
||||
assertThat(url.getParameterString(), allOf(containsString("key2=value2"), containsString("key1=value1")));
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,37 +40,37 @@ import static zutil.net.http.HttpServer.SESSION_KEY_ID;
|
|||
|
||||
public class HttpGuessTheNumber implements HttpPage {
|
||||
|
||||
private static final String SESSION_KEY_NUMBER = "random_number";
|
||||
private static final String REQUEST_KEY_GUESS = "guess";
|
||||
private static final String COOKIE_KEY_LOW = "low";
|
||||
private static final String COOKIE_KEY_HIGH = "high";
|
||||
private static final String SESSION_KEY_NUMBER = "random_number";
|
||||
private static final String REQUEST_KEY_GUESS = "guess";
|
||||
private static final String COOKIE_KEY_LOW = "low";
|
||||
private static final String COOKIE_KEY_HIGH = "high";
|
||||
|
||||
|
||||
public static void main(String[] args) throws IOException{
|
||||
public static void main(String[] args) throws IOException{
|
||||
LogUtil.setGlobalLevel(Level.ALL);
|
||||
LogUtil.setGlobalFormatter(new CompactLogFormatter());
|
||||
|
||||
//HttpServer server = new HttpServer("localhost", 443, FileFinder.find("keySSL"), "rootroot");//SSL
|
||||
HttpServer server = new HttpServer(8080);
|
||||
server.setDefaultPage(new HttpGuessTheNumber());
|
||||
server.run();
|
||||
}
|
||||
HttpServer server = new HttpServer(8080);
|
||||
server.setDefaultPage(new HttpGuessTheNumber());
|
||||
server.run();
|
||||
}
|
||||
|
||||
public void respond(HttpPrintStream out,
|
||||
HttpHeader client_info,
|
||||
Map<String, Object> session,
|
||||
Map<String, String> cookie,
|
||||
Map<String, String> request) throws IOException {
|
||||
public void respond(HttpPrintStream out,
|
||||
HttpHeader client_info,
|
||||
Map<String, Object> session,
|
||||
Map<String, String> cookie,
|
||||
Map<String, String> request) throws IOException {
|
||||
|
||||
out.enableBuffering(true);
|
||||
out.println("<html>");
|
||||
out.println("<H2>Welcome To The Number Guess Game!</H2>");
|
||||
out.enableBuffering(true);
|
||||
out.println("<html>");
|
||||
out.println("<H2>Welcome To The Number Guess Game!</H2>");
|
||||
|
||||
String low = cookie.get(COOKIE_KEY_LOW);
|
||||
String high = cookie.get(COOKIE_KEY_HIGH);
|
||||
String low = cookie.get(COOKIE_KEY_LOW);
|
||||
String high = cookie.get(COOKIE_KEY_HIGH);
|
||||
|
||||
if(session.containsKey(SESSION_KEY_NUMBER)){
|
||||
if (request.containsKey(REQUEST_KEY_GUESS)) {
|
||||
if(session.containsKey(SESSION_KEY_NUMBER)){
|
||||
if (request.containsKey(REQUEST_KEY_GUESS)) {
|
||||
int guess = Integer.parseInt(request.get(REQUEST_KEY_GUESS));
|
||||
int number = (Integer) session.get(SESSION_KEY_NUMBER);
|
||||
|
||||
|
|
@ -93,26 +93,26 @@ public class HttpGuessTheNumber implements HttpPage {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else{
|
||||
session.put(SESSION_KEY_NUMBER, (int)(Math.random()*99+1));
|
||||
low = "0";
|
||||
high = "100";
|
||||
}
|
||||
else{
|
||||
session.put(SESSION_KEY_NUMBER, (int)(Math.random()*99+1));
|
||||
low = "0";
|
||||
high = "100";
|
||||
out.setCookie(COOKIE_KEY_LOW, low);
|
||||
out.setCookie(COOKIE_KEY_HIGH, high);
|
||||
}
|
||||
}
|
||||
|
||||
out.println("<form method='post'>");
|
||||
out.println(low+" < X < "+high+"<br>");
|
||||
out.println("Guess a number between 0 and 100:<br>");
|
||||
out.println("<input type='text' name='guess'>");
|
||||
out.println("<input type='hidden' name='test' value='test'>");
|
||||
out.println("<input type='submit' value='Guess'>");
|
||||
out.println("</form>");
|
||||
out.println("<script>document.all.guess.focus();</script>");
|
||||
out.println("<b>DEBUG: session_id="+session.get(SESSION_KEY_ID)+"</b><br>");
|
||||
out.println("<b>DEBUG: number="+session.get(SESSION_KEY_NUMBER)+"</b><br>");
|
||||
out.println("</html>");
|
||||
}
|
||||
out.println("<form method='post'>");
|
||||
out.println(low+" < X < "+high+"<br>");
|
||||
out.println("Guess a number between 0 and 100:<br>");
|
||||
out.println("<input type='text' name='guess'>");
|
||||
out.println("<input type='hidden' name='test' value='test'>");
|
||||
out.println("<input type='submit' value='Guess'>");
|
||||
out.println("</form>");
|
||||
out.println("<script>document.all.guess.focus();</script>");
|
||||
out.println("<b>DEBUG: session_id="+session.get(SESSION_KEY_ID)+"</b><br>");
|
||||
out.println("<b>DEBUG: number="+session.get(SESSION_KEY_NUMBER)+"</b><br>");
|
||||
out.println("</html>");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,35 +38,35 @@ import java.util.logging.Level;
|
|||
|
||||
@SuppressWarnings("unused")
|
||||
public class NetworkClientTest {
|
||||
public static void main(String[] args) throws NoSuchAlgorithmException, InterruptedException {
|
||||
try {
|
||||
public static void main(String[] args) throws NoSuchAlgorithmException, InterruptedException {
|
||||
try {
|
||||
//LogUtil.setGlobalLevel(Level.ALL);
|
||||
LogUtil.setGlobalFormatter(new CompactLogFormatter());
|
||||
|
||||
int count = 0;
|
||||
long time = System.currentTimeMillis()+1000*60;
|
||||
NioClient client = new NioClient(InetAddress.getByName("localhost"), 6056);
|
||||
StandardWorker worker = new StandardWorker(client);
|
||||
client.setDefaultWorker(worker);
|
||||
long time = System.currentTimeMillis()+1000*60;
|
||||
NioClient client = new NioClient(InetAddress.getByName("localhost"), 6056);
|
||||
StandardWorker worker = new StandardWorker(client);
|
||||
client.setDefaultWorker(worker);
|
||||
|
||||
Thread.sleep(1000);
|
||||
while(time > System.currentTimeMillis()){
|
||||
PrintResponseHandler handler = new PrintResponseHandler();
|
||||
worker.send(client.getRemoteAddress(),
|
||||
while(time > System.currentTimeMillis()){
|
||||
PrintResponseHandler handler = new PrintResponseHandler();
|
||||
worker.send(client.getRemoteAddress(),
|
||||
new StringResponseMessage("StringResponseMessage: "+count),
|
||||
handler);
|
||||
handler.waitForResponse();
|
||||
//Thread.sleep(100);
|
||||
//System.out.println("sending..");
|
||||
count++;
|
||||
}
|
||||
client.close();
|
||||
|
||||
System.out.println("Message Count 1m: "+count);
|
||||
System.out.println("Message Count 1s: "+count/60);
|
||||
System.exit(0);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
handler.waitForResponse();
|
||||
//Thread.sleep(100);
|
||||
//System.out.println("sending..");
|
||||
count++;
|
||||
}
|
||||
client.close();
|
||||
|
||||
System.out.println("Message Count 1m: "+count);
|
||||
System.out.println("Message Count 1s: "+count/60);
|
||||
System.exit(0);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,19 +35,19 @@ import java.util.logging.Level;
|
|||
|
||||
@SuppressWarnings("unused")
|
||||
public class NetworkServerTest {
|
||||
public static void main(String[] args) throws NoSuchAlgorithmException, InterruptedException {
|
||||
try {
|
||||
//LogUtil.setGlobalLevel(Level.ALL);
|
||||
LogUtil.setGlobalFormatter(new CompactLogFormatter());
|
||||
public static void main(String[] args) throws NoSuchAlgorithmException, InterruptedException {
|
||||
try {
|
||||
//LogUtil.setGlobalLevel(Level.ALL);
|
||||
LogUtil.setGlobalFormatter(new CompactLogFormatter());
|
||||
|
||||
NioServer server = new NioServer(6056);
|
||||
server.setDefaultWorker(new StandardWorker(server));
|
||||
NioServer server = new NioServer(6056);
|
||||
server.setDefaultWorker(new StandardWorker(server));
|
||||
|
||||
while(true){
|
||||
Thread.sleep(1000);
|
||||
while(true){
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,41 +33,41 @@ import java.util.logging.Level;
|
|||
|
||||
|
||||
public class UpdateClientTest implements ProgressListener<UpdateClient, FileInfo>{
|
||||
public static void main(String[] args){
|
||||
LogUtil.setLevel("zutil", Level.FINEST);
|
||||
LogUtil.setFormatter("zutil", new CompactLogFormatter());
|
||||
|
||||
UpdateClientTest client = new UpdateClientTest();
|
||||
client.start();
|
||||
}
|
||||
|
||||
public void start(){
|
||||
try {
|
||||
final UpdateClient client = new UpdateClient("localhost", 2000, "C:\\Users\\Ziver\\Desktop\\client");
|
||||
client.setProgressListener(new Zupdater());
|
||||
|
||||
//client.setProgressListener(this);
|
||||
|
||||
EventQueue.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
Zupdater gui = new Zupdater();
|
||||
client.setProgressListener(gui);
|
||||
gui.setVisible(true);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
client.update();
|
||||
client.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
public static void main(String[] args){
|
||||
LogUtil.setLevel("zutil", Level.FINEST);
|
||||
LogUtil.setFormatter("zutil", new CompactLogFormatter());
|
||||
|
||||
public void progressUpdate(UpdateClient source, FileInfo info, double percent) {
|
||||
System.out.println(info+": "+percent+"%");
|
||||
}
|
||||
UpdateClientTest client = new UpdateClientTest();
|
||||
client.start();
|
||||
}
|
||||
|
||||
public void start(){
|
||||
try {
|
||||
final UpdateClient client = new UpdateClient("localhost", 2000, "C:\\Users\\Ziver\\Desktop\\client");
|
||||
client.setProgressListener(new Zupdater());
|
||||
|
||||
//client.setProgressListener(this);
|
||||
|
||||
EventQueue.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
Zupdater gui = new Zupdater();
|
||||
client.setProgressListener(gui);
|
||||
gui.setVisible(true);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
client.update();
|
||||
client.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void progressUpdate(UpdateClient source, FileInfo info, double percent) {
|
||||
System.out.println(info+": "+percent+"%");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,14 +31,14 @@ import java.util.logging.Level;
|
|||
|
||||
|
||||
public class UpdateServerTest {
|
||||
public static void main(String[] args){
|
||||
try {
|
||||
LogUtil.setGlobalLevel(Level.FINEST);
|
||||
LogUtil.setGlobalFormatter(new CompactLogFormatter());
|
||||
|
||||
new UpdateServer(2000, "C:\\Users\\Ziver\\Desktop\\server");
|
||||
}catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
public static void main(String[] args){
|
||||
try {
|
||||
LogUtil.setGlobalLevel(Level.FINEST);
|
||||
LogUtil.setGlobalFormatter(new CompactLogFormatter());
|
||||
|
||||
new UpdateServer(2000, "C:\\Users\\Ziver\\Desktop\\server");
|
||||
}catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,28 +36,28 @@ import java.io.IOException;
|
|||
|
||||
|
||||
public class UPnPServerTest {
|
||||
|
||||
public static void main(String[] args) throws IOException{
|
||||
UPnPMediaServer upnp = new UPnPMediaServer("http://192.168.0.60:8080/");
|
||||
MultiPrintStream.out.println("UPNP Server running");
|
||||
|
||||
UPnPContentDirectory cds = new UPnPContentDirectory(new File("C:\\Users\\Ziver\\Desktop\\lan"));
|
||||
WebServiceDef ws = new WebServiceDef( UPnPContentDirectory.class );
|
||||
|
||||
HttpServer http = new HttpServer(8080);
|
||||
//http.setDefaultPage(upnp);
|
||||
http.setPage("/RootDesc", upnp );
|
||||
http.setPage("/SCP/ContentDir", cds );
|
||||
SOAPHttpPage soap = new SOAPHttpPage(ws);
|
||||
soap.setObject( cds );
|
||||
soap.enableSession( false );
|
||||
http.setPage("/Action/ContentDir", soap );
|
||||
http.start();
|
||||
MultiPrintStream.out.println("HTTP Server running");
|
||||
|
||||
SSDPServer ssdp = new SSDPServer();
|
||||
ssdp.addService( upnp );
|
||||
ssdp.start();
|
||||
MultiPrintStream.out.println("SSDP Server running");
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws IOException{
|
||||
UPnPMediaServer upnp = new UPnPMediaServer("http://192.168.0.60:8080/");
|
||||
MultiPrintStream.out.println("UPNP Server running");
|
||||
|
||||
UPnPContentDirectory cds = new UPnPContentDirectory(new File("C:\\Users\\Ziver\\Desktop\\lan"));
|
||||
WebServiceDef ws = new WebServiceDef( UPnPContentDirectory.class );
|
||||
|
||||
HttpServer http = new HttpServer(8080);
|
||||
//http.setDefaultPage(upnp);
|
||||
http.setPage("/RootDesc", upnp );
|
||||
http.setPage("/SCP/ContentDir", cds );
|
||||
SOAPHttpPage soap = new SOAPHttpPage(ws);
|
||||
soap.setObject( cds );
|
||||
soap.enableSession( false );
|
||||
http.setPage("/Action/ContentDir", soap );
|
||||
http.start();
|
||||
MultiPrintStream.out.println("HTTP Server running");
|
||||
|
||||
SSDPServer ssdp = new SSDPServer();
|
||||
ssdp.addService( upnp );
|
||||
ssdp.start();
|
||||
MultiPrintStream.out.println("SSDP Server running");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,20 +36,20 @@ import java.util.logging.Level;
|
|||
// TODO: COnvert to JUnit
|
||||
public class SOAPClientTest {
|
||||
|
||||
public static void main(String[] args) throws InstantiationException, IllegalAccessException, MalformedURLException {
|
||||
LogUtil.setGlobalLevel(Level.ALL);
|
||||
LogUtil.setFormatter("", new CompactLogFormatter());
|
||||
|
||||
TestClient intf = SOAPClientFactory.createClient(new URL("http://localhost:3289"), TestClient.class);
|
||||
intf.m();
|
||||
intf.c();
|
||||
}
|
||||
|
||||
|
||||
public interface TestClient extends WSInterface{
|
||||
public void m();
|
||||
|
||||
public void c();
|
||||
public static void main(String[] args) throws InstantiationException, IllegalAccessException, MalformedURLException {
|
||||
LogUtil.setGlobalLevel(Level.ALL);
|
||||
LogUtil.setFormatter("", new CompactLogFormatter());
|
||||
|
||||
}
|
||||
TestClient intf = SOAPClientFactory.createClient(new URL("http://localhost:3289"), TestClient.class);
|
||||
intf.m();
|
||||
intf.c();
|
||||
}
|
||||
|
||||
|
||||
public interface TestClient extends WSInterface{
|
||||
public void m();
|
||||
|
||||
public void c();
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,116 +37,116 @@ import zutil.parser.wsdl.WSDLWriter;
|
|||
// TODO: Convert to JUnit
|
||||
public class SOAPTest {
|
||||
/************************* TEST CASES ************************/
|
||||
public static void main(String[] args){
|
||||
WebServiceDef wsDef = new WebServiceDef( MainSOAPClass.class );
|
||||
SOAPHttpPage soap = new SOAPHttpPage( wsDef );
|
||||
public static void main(String[] args){
|
||||
WebServiceDef wsDef = new WebServiceDef( MainSOAPClass.class );
|
||||
SOAPHttpPage soap = new SOAPHttpPage( wsDef );
|
||||
|
||||
System.out.println( "****************** WSDL *********************" );
|
||||
WSDLWriter wsdl = new WSDLWriter( wsDef );
|
||||
wsdl.write(System.out);
|
||||
|
||||
// Response
|
||||
try {
|
||||
System.out.println( "\n****************** REQUEST *********************" );
|
||||
String request = "<?xml version=\"1.0\"?>\n" +
|
||||
"<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">\n" +
|
||||
" <soap:Body xmlns:m=\"http://www.example.org/stock\">\n" +
|
||||
" <m:stringArrayMethod>\n" +
|
||||
" <m:StringName>IBM</m:StringName>\n" +
|
||||
" </m:stringArrayMethod>\n" +
|
||||
System.out.println( "****************** WSDL *********************" );
|
||||
WSDLWriter wsdl = new WSDLWriter( wsDef );
|
||||
wsdl.write(System.out);
|
||||
|
||||
" <m:simpleReturnClassMethod>\n" +
|
||||
" <m:byte>IBM</m:byte>\n" +
|
||||
" </m:simpleReturnClassMethod>\n" +
|
||||
" </soap:Body>\n" +
|
||||
"</soap:Envelope>";
|
||||
System.out.println(request);
|
||||
// Response
|
||||
try {
|
||||
System.out.println( "\n****************** REQUEST *********************" );
|
||||
String request = "<?xml version=\"1.0\"?>\n" +
|
||||
"<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">\n" +
|
||||
" <soap:Body xmlns:m=\"http://www.example.org/stock\">\n" +
|
||||
" <m:stringArrayMethod>\n" +
|
||||
" <m:StringName>IBM</m:StringName>\n" +
|
||||
" </m:stringArrayMethod>\n" +
|
||||
|
||||
" <m:simpleReturnClassMethod>\n" +
|
||||
" <m:byte>IBM</m:byte>\n" +
|
||||
" </m:simpleReturnClassMethod>\n" +
|
||||
" </soap:Body>\n" +
|
||||
"</soap:Envelope>";
|
||||
System.out.println(request);
|
||||
System.out.println( "\n****************** EXECUTION *********************" );
|
||||
Document document = soap.genSOAPResponse(request);
|
||||
System.out.println( "\n****************** RESPONSE *********************" );
|
||||
Document document = soap.genSOAPResponse(request);
|
||||
System.out.println( "\n****************** RESPONSE *********************" );
|
||||
|
||||
OutputFormat format = OutputFormat.createPrettyPrint();
|
||||
XMLWriter writer = new XMLWriter( System.out, format );
|
||||
writer.write( document );
|
||||
OutputFormat format = OutputFormat.createPrettyPrint();
|
||||
XMLWriter writer = new XMLWriter( System.out, format );
|
||||
writer.write( document );
|
||||
|
||||
System.out.println();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
System.out.println();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/************************* TEST CLASSES ************************/
|
||||
@SuppressWarnings("unused")
|
||||
public static class SpecialReturnClass extends WSReturnObject{
|
||||
@WSValueName(value="otherValue1")
|
||||
public String param1 = "otherValue1";
|
||||
@WSValueName("otherName2")
|
||||
public String param2 = "otherValue2";
|
||||
public byte[] b = new byte[]{0x12, 0x23};
|
||||
public InnerClass inner = new InnerClass();
|
||||
}
|
||||
public static class SpecialReturnClass extends WSReturnObject{
|
||||
@WSValueName(value="otherValue1")
|
||||
public String param1 = "otherValue1";
|
||||
@WSValueName("otherName2")
|
||||
public String param2 = "otherValue2";
|
||||
public byte[] b = new byte[]{0x12, 0x23};
|
||||
public InnerClass inner = new InnerClass();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public static class InnerClass extends WSReturnObject{
|
||||
public String innerClassParam1 = "innerClass1";
|
||||
public String innerClassParam2 = "innerClass2";
|
||||
}
|
||||
public static class InnerClass extends WSReturnObject{
|
||||
public String innerClassParam1 = "innerClass1";
|
||||
public String innerClassParam2 = "innerClass2";
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public static class SimpleReturnClass extends WSReturnObject{
|
||||
@WSValueName("otherParam1")
|
||||
public String param1 = "param1";
|
||||
public String param2 = "param2";
|
||||
}
|
||||
public static class SimpleReturnClass extends WSReturnObject{
|
||||
@WSValueName("otherParam1")
|
||||
public String param1 = "param1";
|
||||
public String param2 = "param2";
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@WSNamespace("http://test.se:8080/")
|
||||
public static class MainSOAPClass implements WSInterface{
|
||||
public MainSOAPClass(){}
|
||||
|
||||
@WSHeader()
|
||||
@WSDocumentation("Documentation of method exceptionMethod()")
|
||||
public void exceptionMethod(
|
||||
@WSParamName(value="otherParam1", optional=true) int param1,
|
||||
@WSParamName(value="otherParam2", optional=true) int param2) throws Exception{
|
||||
System.out.println("Executing method: exceptionMethod(int param1="+param1+", int param2="+param2+",)");
|
||||
throw new Exception("This is an Exception");
|
||||
}
|
||||
@WSNamespace("http://test.se:8080/")
|
||||
public static class MainSOAPClass implements WSInterface{
|
||||
public MainSOAPClass(){}
|
||||
|
||||
@WSReturnName("stringArray")
|
||||
@WSParamDocumentation("Documentation of stringArrayMethod()")
|
||||
public String[][] stringArrayMethod (
|
||||
@WSParamName("StringName") String str) throws Exception{
|
||||
System.out.println("Executing method: stringArrayMethod(String str='"+str+"')");
|
||||
return new String[][]{{"test","test2"},{"test3","test4"}};
|
||||
}
|
||||
@WSHeader()
|
||||
@WSDocumentation("Documentation of method exceptionMethod()")
|
||||
public void exceptionMethod(
|
||||
@WSParamName(value="otherParam1", optional=true) int param1,
|
||||
@WSParamName(value="otherParam2", optional=true) int param2) throws Exception{
|
||||
System.out.println("Executing method: exceptionMethod(int param1="+param1+", int param2="+param2+",)");
|
||||
throw new Exception("This is an Exception");
|
||||
}
|
||||
|
||||
@WSReturnName("specialReturnClass")
|
||||
@WSParamDocumentation("Documentation of specialReturnMethod()")
|
||||
public SpecialReturnClass[] specialReturnMethod (
|
||||
@WSParamName("StringName2") String str) throws Exception{
|
||||
System.out.println("Executing method: specialReturnMethod(String str='"+str+"')");
|
||||
return new SpecialReturnClass[]{new SpecialReturnClass(), new SpecialReturnClass()};
|
||||
}
|
||||
@WSReturnName("stringArray")
|
||||
@WSParamDocumentation("Documentation of stringArrayMethod()")
|
||||
public String[][] stringArrayMethod (
|
||||
@WSParamName("StringName") String str) throws Exception{
|
||||
System.out.println("Executing method: stringArrayMethod(String str='"+str+"')");
|
||||
return new String[][]{{"test","test2"},{"test3","test4"}};
|
||||
}
|
||||
|
||||
@WSReturnName("SimpleReturnClass")
|
||||
@WSParamDocumentation("null is the kala")
|
||||
public SimpleReturnClass simpleReturnClassMethod (
|
||||
@WSParamName("byte") String lol) throws Exception{
|
||||
System.out.println("Executing method: simpleReturnClassMethod()");
|
||||
SimpleReturnClass tmp = new SimpleReturnClass();
|
||||
tmp.param1 = "newParam1";
|
||||
tmp.param2 = "newParam2";
|
||||
return tmp;
|
||||
}
|
||||
|
||||
@WSParamDocumentation("void method documentation")
|
||||
public void voidMethod (){ }
|
||||
|
||||
@WSIgnore()
|
||||
public void disabledMethod(){ }
|
||||
protected void protectedMethod(){ }
|
||||
@WSReturnName("specialReturnClass")
|
||||
@WSParamDocumentation("Documentation of specialReturnMethod()")
|
||||
public SpecialReturnClass[] specialReturnMethod (
|
||||
@WSParamName("StringName2") String str) throws Exception{
|
||||
System.out.println("Executing method: specialReturnMethod(String str='"+str+"')");
|
||||
return new SpecialReturnClass[]{new SpecialReturnClass(), new SpecialReturnClass()};
|
||||
}
|
||||
|
||||
private void privateMethod(){ }
|
||||
}
|
||||
@WSReturnName("SimpleReturnClass")
|
||||
@WSParamDocumentation("null is the kala")
|
||||
public SimpleReturnClass simpleReturnClassMethod (
|
||||
@WSParamName("byte") String lol) throws Exception{
|
||||
System.out.println("Executing method: simpleReturnClassMethod()");
|
||||
SimpleReturnClass tmp = new SimpleReturnClass();
|
||||
tmp.param1 = "newParam1";
|
||||
tmp.param2 = "newParam2";
|
||||
return tmp;
|
||||
}
|
||||
|
||||
@WSParamDocumentation("void method documentation")
|
||||
public void voidMethod (){ }
|
||||
|
||||
@WSIgnore()
|
||||
public void disabledMethod(){ }
|
||||
protected void protectedMethod(){ }
|
||||
|
||||
private void privateMethod(){ }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,18 +31,18 @@ import static org.junit.Assert.assertEquals;
|
|||
|
||||
public class BBCodeParserTest{
|
||||
|
||||
@Test
|
||||
public void BBCodeParser() {
|
||||
BBCodeParser parser = new BBCodeParser();
|
||||
|
||||
assertEquals("1234", parser.read("1234"));
|
||||
assertEquals("<i>1234</i>", parser.read("[i]1234[/i]"));
|
||||
assertEquals("[apa]lol[/apa]", parser.read("[apa]lol[/apa]"));
|
||||
assertEquals("jshdkj <u>lol [apa]lol[/apa]</u>", parser.read("jshdkj [u]lol [apa]lol[/apa]"));
|
||||
//assertEquals("jshdkj [m]lol[/k] <i>lol</i>", parser.read("jshdkj [m]lol[/k] [i]lol[/i]"));
|
||||
assertEquals("jshdkj [m", parser.read("jshdkj [m"));
|
||||
assertEquals("jshdkj [/m", parser.read("jshdkj [/m"));
|
||||
assertEquals("jshdkj m]", parser.read("jshdkj m]"));
|
||||
assertEquals("jshdkj <br />", parser.read("jshdkj <br />"));
|
||||
}
|
||||
@Test
|
||||
public void BBCodeParser() {
|
||||
BBCodeParser parser = new BBCodeParser();
|
||||
|
||||
assertEquals("1234", parser.read("1234"));
|
||||
assertEquals("<i>1234</i>", parser.read("[i]1234[/i]"));
|
||||
assertEquals("[apa]lol[/apa]", parser.read("[apa]lol[/apa]"));
|
||||
assertEquals("jshdkj <u>lol [apa]lol[/apa]</u>", parser.read("jshdkj [u]lol [apa]lol[/apa]"));
|
||||
//assertEquals("jshdkj [m]lol[/k] <i>lol</i>", parser.read("jshdkj [m]lol[/k] [i]lol[/i]"));
|
||||
assertEquals("jshdkj [m", parser.read("jshdkj [m"));
|
||||
assertEquals("jshdkj [/m", parser.read("jshdkj [/m"));
|
||||
assertEquals("jshdkj m]", parser.read("jshdkj m]"));
|
||||
assertEquals("jshdkj <br />", parser.read("jshdkj <br />"));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,41 +33,41 @@ import static org.junit.Assert.assertEquals;
|
|||
|
||||
public class Base64Test {
|
||||
|
||||
@Test
|
||||
public void decode() {
|
||||
@Test
|
||||
public void decode() {
|
||||
assertEquals( "Man is distinguished, not only by his reason, but by this singular passion from other animals, which is a lust of the mind, that by a perseverance of delight in the continued and indefatigable generation of knowledge, exceeds the short vehemence of any carnal pleasure.",
|
||||
Base64Decoder.decode("TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dCBieSB0aGlzIHNpbmd1bGFyIHBhc3Npb24gZnJvbSBvdGhlciBhbmltYWxzLCB3aGljaCBpcyBhIGx1c3Qgb2YgdGhlIG1pbmQsIHRoYXQgYnkgYSBwZXJzZXZlcmFuY2Ugb2YgZGVsaWdodCBpbiB0aGUgY29udGludWVkIGFuZCBpbmRlZmF0aWdhYmxlIGdlbmVyYXRpb24gb2Yga25vd2xlZGdlLCBleGNlZWRzIHRoZSBzaG9ydCB2ZWhlbWVuY2Ugb2YgYW55IGNhcm5hbCBwbGVhc3VyZS4=")
|
||||
);
|
||||
);
|
||||
|
||||
Base64Decoder decoder = new Base64Decoder();
|
||||
decoder.clear();
|
||||
decoder.read("YW55IGNhcm5hbCBwbGVhc3VyZQ==");
|
||||
assertEquals( "any carnal pleasure", decoder.toString() );
|
||||
decoder.clear();
|
||||
decoder.read("bGVhc3VyZS4=");
|
||||
assertEquals( "leasure.", decoder.toString() );
|
||||
decoder.clear();
|
||||
decoder.read("YW55IGNhcm5hbCBwbGVhc3Vy");
|
||||
assertEquals( "any carnal pleasur", decoder.toString() );
|
||||
decoder.clear();
|
||||
}
|
||||
decoder.clear();
|
||||
decoder.read("YW55IGNhcm5hbCBwbGVhc3VyZQ==");
|
||||
assertEquals( "any carnal pleasure", decoder.toString() );
|
||||
decoder.clear();
|
||||
decoder.read("bGVhc3VyZS4=");
|
||||
assertEquals( "leasure.", decoder.toString() );
|
||||
decoder.clear();
|
||||
decoder.read("YW55IGNhcm5hbCBwbGVhc3Vy");
|
||||
assertEquals( "any carnal pleasur", decoder.toString() );
|
||||
decoder.clear();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void encode() {
|
||||
assertEquals("TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dCBieSB0aGlzIHNpbmd1bGFyIHBhc3Npb24gZnJvbSBvdGhlciBhbmltYWxzLCB3aGljaCBpcyBhIGx1c3Qgb2YgdGhlIG1pbmQsIHRoYXQgYnkgYSBwZXJzZXZlcmFuY2Ugb2YgZGVsaWdodCBpbiB0aGUgY29udGludWVkIGFuZCBpbmRlZmF0aWdhYmxlIGdlbmVyYXRpb24gb2Yga25vd2xlZGdlLCBleGNlZWRzIHRoZSBzaG9ydCB2ZWhlbWVuY2Ugb2YgYW55IGNhcm5hbCBwbGVhc3VyZS4=" ,
|
||||
Base64Encoder.encode("Man is distinguished, not only by his reason, but by this singular passion from other animals, which is a lust of the mind, that by a perseverance of delight in the continued and indefatigable generation of knowledge, exceeds the short vehemence of any carnal pleasure.")
|
||||
);
|
||||
@Test
|
||||
public void encode() {
|
||||
assertEquals("TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dCBieSB0aGlzIHNpbmd1bGFyIHBhc3Npb24gZnJvbSBvdGhlciBhbmltYWxzLCB3aGljaCBpcyBhIGx1c3Qgb2YgdGhlIG1pbmQsIHRoYXQgYnkgYSBwZXJzZXZlcmFuY2Ugb2YgZGVsaWdodCBpbiB0aGUgY29udGludWVkIGFuZCBpbmRlZmF0aWdhYmxlIGdlbmVyYXRpb24gb2Yga25vd2xlZGdlLCBleGNlZWRzIHRoZSBzaG9ydCB2ZWhlbWVuY2Ugb2YgYW55IGNhcm5hbCBwbGVhc3VyZS4=" ,
|
||||
Base64Encoder.encode("Man is distinguished, not only by his reason, but by this singular passion from other animals, which is a lust of the mind, that by a perseverance of delight in the continued and indefatigable generation of knowledge, exceeds the short vehemence of any carnal pleasure.")
|
||||
);
|
||||
|
||||
assertEquals("YW55IGNhcm5hbCBwbGVhc3VyZQ==", Base64Encoder.encode("any carnal pleasure"));
|
||||
assertEquals("bGVhc3VyZS4=", Base64Encoder.encode("leasure."));
|
||||
assertEquals("YW55IGNhcm5hbCBwbGVhc3Vy", Base64Encoder.encode("any carnal pleasur"));
|
||||
}
|
||||
assertEquals("YW55IGNhcm5hbCBwbGVhc3VyZQ==", Base64Encoder.encode("any carnal pleasure"));
|
||||
assertEquals("bGVhc3VyZS4=", Base64Encoder.encode("leasure."));
|
||||
assertEquals("YW55IGNhcm5hbCBwbGVhc3Vy", Base64Encoder.encode("any carnal pleasur"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void encodeJavaUtil() {
|
||||
assertEquals("TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dCBieSB0aGlzIHNpbmd1bGFyIHBhc3Npb24gZnJvbSBvdGhlciBhbmltYWxzLCB3aGljaCBpcyBhIGx1c3Qgb2YgdGhlIG1pbmQsIHRoYXQgYnkgYSBwZXJzZXZlcmFuY2Ugb2YgZGVsaWdodCBpbiB0aGUgY29udGludWVkIGFuZCBpbmRlZmF0aWdhYmxlIGdlbmVyYXRpb24gb2Yga25vd2xlZGdlLCBleGNlZWRzIHRoZSBzaG9ydCB2ZWhlbWVuY2Ugb2YgYW55IGNhcm5hbCBwbGVhc3VyZS4=" ,
|
||||
Base64.getEncoder().encodeToString("Man is distinguished, not only by his reason, but by this singular passion from other animals, which is a lust of the mind, that by a perseverance of delight in the continued and indefatigable generation of knowledge, exceeds the short vehemence of any carnal pleasure.".getBytes())
|
||||
);
|
||||
assertEquals("TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dCBieSB0aGlzIHNpbmd1bGFyIHBhc3Npb24gZnJvbSBvdGhlciBhbmltYWxzLCB3aGljaCBpcyBhIGx1c3Qgb2YgdGhlIG1pbmQsIHRoYXQgYnkgYSBwZXJzZXZlcmFuY2Ugb2YgZGVsaWdodCBpbiB0aGUgY29udGludWVkIGFuZCBpbmRlZmF0aWdhYmxlIGdlbmVyYXRpb24gb2Yga25vd2xlZGdlLCBleGNlZWRzIHRoZSBzaG9ydCB2ZWhlbWVuY2Ugb2YgYW55IGNhcm5hbCBwbGVhc3VyZS4=" ,
|
||||
Base64.getEncoder().encodeToString("Man is distinguished, not only by his reason, but by this singular passion from other animals, which is a lust of the mind, that by a perseverance of delight in the continued and indefatigable generation of knowledge, exceeds the short vehemence of any carnal pleasure.".getBytes())
|
||||
);
|
||||
|
||||
assertEquals("YW55IGNhcm5hbCBwbGVhc3VyZQ==", Base64.getEncoder().encodeToString("any carnal pleasure".getBytes()));
|
||||
assertEquals("bGVhc3VyZS4=", Base64.getEncoder().encodeToString("leasure.".getBytes()));
|
||||
|
|
|
|||
|
|
@ -147,36 +147,36 @@ public class JSONParserTest {
|
|||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void complexMap() {
|
||||
String json = "{" +
|
||||
"\"test1\": 1234," +
|
||||
"\"TEST1\": 5678," +
|
||||
"\"test3\": 1234.99," +
|
||||
"\"test4\": \"91011\"," +
|
||||
"\"test5\": [12,13,14,15]," +
|
||||
"\"test6\": [\"a\",\"b\",\"c\",\"d\"]" +
|
||||
"}";
|
||||
|
||||
DataNode data = JSONParser.read(json);
|
||||
assert( data.isMap() );
|
||||
assert( 1234 == data.get("test1").getInt() );
|
||||
assert( 5678 == data.get("TEST1").getInt() );
|
||||
assert( 1234.99 == data.get("test3").getDouble() );
|
||||
assertEquals( "91011", data.get("test4").getString() );
|
||||
|
||||
assert( data.get("test5").isList() );
|
||||
assertEquals( 4, data.get("test5").size() );
|
||||
assertEquals( 12, data.get("test5").get(0).getInt() );
|
||||
assertEquals( 13, data.get("test5").get(1).getInt() );
|
||||
assertEquals( 14, data.get("test5").get(2).getInt() );
|
||||
assertEquals( 15, data.get("test5").get(3).getInt() );
|
||||
|
||||
assert( data.get("test6").isList() );
|
||||
assertEquals( 4, data.get("test6").size() );
|
||||
assertEquals( "a", data.get("test6").get(0).getString() );
|
||||
assertEquals( "b", data.get("test6").get(1).getString() );
|
||||
assertEquals( "c", data.get("test6").get(2).getString() );
|
||||
assertEquals( "d", data.get("test6").get(3).getString() );
|
||||
}
|
||||
@Test
|
||||
public void complexMap() {
|
||||
String json = "{" +
|
||||
"\"test1\": 1234," +
|
||||
"\"TEST1\": 5678," +
|
||||
"\"test3\": 1234.99," +
|
||||
"\"test4\": \"91011\"," +
|
||||
"\"test5\": [12,13,14,15]," +
|
||||
"\"test6\": [\"a\",\"b\",\"c\",\"d\"]" +
|
||||
"}";
|
||||
|
||||
DataNode data = JSONParser.read(json);
|
||||
assert( data.isMap() );
|
||||
assert( 1234 == data.get("test1").getInt() );
|
||||
assert( 5678 == data.get("TEST1").getInt() );
|
||||
assert( 1234.99 == data.get("test3").getDouble() );
|
||||
assertEquals( "91011", data.get("test4").getString() );
|
||||
|
||||
assert( data.get("test5").isList() );
|
||||
assertEquals( 4, data.get("test5").size() );
|
||||
assertEquals( 12, data.get("test5").get(0).getInt() );
|
||||
assertEquals( 13, data.get("test5").get(1).getInt() );
|
||||
assertEquals( 14, data.get("test5").get(2).getInt() );
|
||||
assertEquals( 15, data.get("test5").get(3).getInt() );
|
||||
|
||||
assert( data.get("test6").isList() );
|
||||
assertEquals( 4, data.get("test6").size() );
|
||||
assertEquals( "a", data.get("test6").get(0).getString() );
|
||||
assertEquals( "b", data.get("test6").get(1).getString() );
|
||||
assertEquals( "c", data.get("test6").get(2).getString() );
|
||||
assertEquals( "d", data.get("test6").get(3).getString() );
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,19 +51,19 @@ public class JSONSerializerTest{
|
|||
assertThat(data, containsString("'value': 42"));
|
||||
assertThat(data, containsString("'decimal': 1.1"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInputSerializerWithPrimitives() throws InterruptedException, IOException, ClassNotFoundException{
|
||||
TestClass sourceObj = new TestClass().init();
|
||||
|
||||
TestClass targetObj = sendReceiveObject(sourceObj);
|
||||
|
||||
@Test
|
||||
public void testInputSerializerWithPrimitives() throws InterruptedException, IOException, ClassNotFoundException{
|
||||
TestClass sourceObj = new TestClass().init();
|
||||
|
||||
TestClass targetObj = sendReceiveObject(sourceObj);
|
||||
|
||||
TestClass.assertEquals(sourceObj, targetObj);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOutputSerializerWithClones() throws InterruptedException, IOException, ClassNotFoundException{
|
||||
TestClassObjClone sourceObj = new TestClassObjClone().init();
|
||||
TestClassObjClone sourceObj = new TestClassObjClone().init();
|
||||
|
||||
String data = writeObjectToJson(sourceObj);
|
||||
data = data.replace("\"", "'");
|
||||
|
|
@ -72,15 +72,15 @@ public class JSONSerializerTest{
|
|||
assertThat(data, containsString("'obj1': {'@class': 'zutil.parser.json.JSONSerializerTest$TestObj', '@object_id': 2, 'value': 42}"));
|
||||
assertThat(data, containsString("'obj2': {'@object_id': 2}"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInputSerializerWithClones() throws InterruptedException, IOException, ClassNotFoundException{
|
||||
TestClassObjClone sourceObj = new TestClassObjClone().init();
|
||||
|
||||
TestClassObjClone targetObj = sendReceiveObject(sourceObj);
|
||||
|
||||
assertEquals( sourceObj, targetObj );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInputSerializerWithClones() throws InterruptedException, IOException, ClassNotFoundException{
|
||||
TestClassObjClone sourceObj = new TestClassObjClone().init();
|
||||
|
||||
TestClassObjClone targetObj = sendReceiveObject(sourceObj);
|
||||
|
||||
assertEquals( sourceObj, targetObj );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOutputSerializerWithArrays() throws InterruptedException, IOException, ClassNotFoundException{
|
||||
|
|
@ -110,27 +110,27 @@ public class JSONSerializerTest{
|
|||
assertEquals( sourceObj, targetObj );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSerializerWithNullFieldsHidden() throws InterruptedException, IOException, ClassNotFoundException{
|
||||
TestClass sourceObj = new TestClass();
|
||||
@Test
|
||||
public void testSerializerWithNullFieldsHidden() throws InterruptedException, IOException, ClassNotFoundException{
|
||||
TestClass sourceObj = new TestClass();
|
||||
|
||||
String data = writeObjectToJson(sourceObj, false);
|
||||
data = data.replace("\"", "'");
|
||||
assertEquals(
|
||||
"{'decimal': 0.0}",
|
||||
data);
|
||||
String data = writeObjectToJson(sourceObj, false);
|
||||
data = data.replace("\"", "'");
|
||||
assertEquals(
|
||||
"{'decimal': 0.0}",
|
||||
data);
|
||||
|
||||
TestClass targetObj = sendReceiveObject(sourceObj);
|
||||
TestClass.assertEquals(sourceObj, targetObj);
|
||||
}
|
||||
TestClass.assertEquals(sourceObj, targetObj);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSerializerWithMapField() throws InterruptedException, IOException, ClassNotFoundException{
|
||||
@Test
|
||||
public void testSerializerWithMapField() throws InterruptedException, IOException, ClassNotFoundException{
|
||||
TestClassMap sourceObj = new TestClassMap().init();
|
||||
|
||||
TestClassMap targetObj = sendReceiveObject(sourceObj);
|
||||
TestClassMap.assertEquals(sourceObj, targetObj);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSerializerWithMapFieldWithNullEntry() throws InterruptedException, IOException, ClassNotFoundException{
|
||||
|
|
@ -173,95 +173,95 @@ public class JSONSerializerTest{
|
|||
TestClass.assertEquals(sourceObj2, targetObj2);
|
||||
}
|
||||
|
||||
/******************* Utility Functions ************************************/
|
||||
|
||||
public static <T> T sendReceiveObject(T sourceObj) throws IOException{
|
||||
return readObjectFromJson(
|
||||
writeObjectToJson(sourceObj));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
/******************* Utility Functions ************************************/
|
||||
|
||||
public static <T> T sendReceiveObject(T sourceObj) throws IOException{
|
||||
return readObjectFromJson(
|
||||
writeObjectToJson(sourceObj));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> T readObjectFromJson(String json) throws IOException{
|
||||
StringReader bin = new StringReader(json);
|
||||
JSONObjectInputStream in = new JSONObjectInputStream(bin);
|
||||
T targetObj = (T) in.readObject();
|
||||
in.close();
|
||||
|
||||
return targetObj;
|
||||
}
|
||||
StringReader bin = new StringReader(json);
|
||||
JSONObjectInputStream in = new JSONObjectInputStream(bin);
|
||||
T targetObj = (T) in.readObject();
|
||||
in.close();
|
||||
|
||||
public static <T> String writeObjectToJson(T sourceObj) throws IOException{
|
||||
return writeObjectToJson(sourceObj, true);
|
||||
}
|
||||
return targetObj;
|
||||
}
|
||||
|
||||
public static <T> String writeObjectToJson(T sourceObj) throws IOException{
|
||||
return writeObjectToJson(sourceObj, true);
|
||||
}
|
||||
public static <T> String writeObjectToJson(T sourceObj, boolean metadata) throws IOException{
|
||||
StringOutputStream bout = new StringOutputStream();
|
||||
JSONObjectOutputStream out = new JSONObjectOutputStream(bout);
|
||||
out.enableMetaData(metadata);
|
||||
StringOutputStream bout = new StringOutputStream();
|
||||
JSONObjectOutputStream out = new JSONObjectOutputStream(bout);
|
||||
out.enableMetaData(metadata);
|
||||
|
||||
out.writeObject(sourceObj);
|
||||
out.flush();
|
||||
out.close();
|
||||
|
||||
String data = bout.toString();
|
||||
out.writeObject(sourceObj);
|
||||
out.flush();
|
||||
out.close();
|
||||
|
||||
String data = bout.toString();
|
||||
return data;
|
||||
}
|
||||
|
||||
/******************** Test Classes ************************************/
|
||||
|
||||
public static class TestClass implements Serializable{
|
||||
private static final long serialVersionUID = 1L;
|
||||
String str;
|
||||
double decimal;
|
||||
TestObj obj1;
|
||||
TestObj obj2;
|
||||
|
||||
public TestClass init(){
|
||||
this.str = "abcd";
|
||||
this.decimal = 1.1;
|
||||
this.obj1 = new TestObj().init();
|
||||
this.obj2 = new TestObj().init();
|
||||
return this;
|
||||
}
|
||||
|
||||
public static void assertEquals(TestClass obj1, TestClass obj2){
|
||||
Assert.assertEquals(obj1.str, obj2.str);
|
||||
Assert.assertEquals(obj1.decimal, obj2.decimal, 0.001);
|
||||
Assert.assertEquals(obj1.obj1, obj2.obj1);
|
||||
Assert.assertEquals(obj1.obj2, obj2.obj2);
|
||||
}
|
||||
}
|
||||
|
||||
public static class TestClassObjClone{
|
||||
TestObj obj1;
|
||||
TestObj obj2;
|
||||
|
||||
public TestClassObjClone init(){
|
||||
this.obj1 = this.obj2 = new TestObj().init();
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean equals(Object obj){
|
||||
return obj instanceof TestClassObjClone &&
|
||||
this.obj1.equals(((TestClassObjClone)obj).obj1) &&
|
||||
this.obj1 == this.obj2 &&
|
||||
((TestClassObjClone)obj).obj1 == ((TestClassObjClone)obj).obj2;
|
||||
}
|
||||
}
|
||||
|
||||
public static class TestObj implements Serializable{
|
||||
private static final long serialVersionUID = 1L;
|
||||
int value;
|
||||
|
||||
public TestObj init(){
|
||||
this.value = 42;
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean equals(Object obj){
|
||||
return obj instanceof TestObj &&
|
||||
}
|
||||
|
||||
/******************** Test Classes ************************************/
|
||||
|
||||
public static class TestClass implements Serializable{
|
||||
private static final long serialVersionUID = 1L;
|
||||
String str;
|
||||
double decimal;
|
||||
TestObj obj1;
|
||||
TestObj obj2;
|
||||
|
||||
public TestClass init(){
|
||||
this.str = "abcd";
|
||||
this.decimal = 1.1;
|
||||
this.obj1 = new TestObj().init();
|
||||
this.obj2 = new TestObj().init();
|
||||
return this;
|
||||
}
|
||||
|
||||
public static void assertEquals(TestClass obj1, TestClass obj2){
|
||||
Assert.assertEquals(obj1.str, obj2.str);
|
||||
Assert.assertEquals(obj1.decimal, obj2.decimal, 0.001);
|
||||
Assert.assertEquals(obj1.obj1, obj2.obj1);
|
||||
Assert.assertEquals(obj1.obj2, obj2.obj2);
|
||||
}
|
||||
}
|
||||
|
||||
public static class TestClassObjClone{
|
||||
TestObj obj1;
|
||||
TestObj obj2;
|
||||
|
||||
public TestClassObjClone init(){
|
||||
this.obj1 = this.obj2 = new TestObj().init();
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean equals(Object obj){
|
||||
return obj instanceof TestClassObjClone &&
|
||||
this.obj1.equals(((TestClassObjClone)obj).obj1) &&
|
||||
this.obj1 == this.obj2 &&
|
||||
((TestClassObjClone)obj).obj1 == ((TestClassObjClone)obj).obj2;
|
||||
}
|
||||
}
|
||||
|
||||
public static class TestObj implements Serializable{
|
||||
private static final long serialVersionUID = 1L;
|
||||
int value;
|
||||
|
||||
public TestObj init(){
|
||||
this.value = 42;
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean equals(Object obj){
|
||||
return obj instanceof TestObj &&
|
||||
this.value == ((TestObj)obj).value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class TestClassArray{
|
||||
private int[] array;
|
||||
|
|
|
|||
|
|
@ -34,54 +34,54 @@ import java.util.Random;
|
|||
/**
|
||||
* This code may be used, modified, and redistributed provided that the
|
||||
* author tag below remains intact.
|
||||
*
|
||||
*
|
||||
* @author Ian Clarke <ian@uprizer.com>
|
||||
*/
|
||||
|
||||
public class BloomFilterTest extends TestCase {
|
||||
public void testBloomFilter() {
|
||||
DecimalFormat df = new DecimalFormat("0.00000");
|
||||
Random r = new Random(124445l);
|
||||
int bfSize = 400000;
|
||||
System.out.println("Testing " + bfSize + " bit SimpleBloomFilter");
|
||||
for (int i = 5; i < 10; i++) {
|
||||
int addCount = 10000 * (i + 1);
|
||||
BloomFilter<Integer> bf = new BloomFilter<Integer>(bfSize, addCount);
|
||||
HashSet<Integer> added = new HashSet<Integer>();
|
||||
for (int x = 0; x < addCount; x++) {
|
||||
int num = r.nextInt();
|
||||
added.add(num);
|
||||
}
|
||||
bf.addAll(added);
|
||||
assertTrue("Assert that there are no false negatives", bf
|
||||
.containsAll(added));
|
||||
public void testBloomFilter() {
|
||||
DecimalFormat df = new DecimalFormat("0.00000");
|
||||
Random r = new Random(124445l);
|
||||
int bfSize = 400000;
|
||||
System.out.println("Testing " + bfSize + " bit SimpleBloomFilter");
|
||||
for (int i = 5; i < 10; i++) {
|
||||
int addCount = 10000 * (i + 1);
|
||||
BloomFilter<Integer> bf = new BloomFilter<Integer>(bfSize, addCount);
|
||||
HashSet<Integer> added = new HashSet<Integer>();
|
||||
for (int x = 0; x < addCount; x++) {
|
||||
int num = r.nextInt();
|
||||
added.add(num);
|
||||
}
|
||||
bf.addAll(added);
|
||||
assertTrue("Assert that there are no false negatives", bf
|
||||
.containsAll(added));
|
||||
|
||||
int falsePositives = 0;
|
||||
for (int x = 0; x < addCount; x++) {
|
||||
int num = r.nextInt();
|
||||
int falsePositives = 0;
|
||||
for (int x = 0; x < addCount; x++) {
|
||||
int num = r.nextInt();
|
||||
|
||||
// Ensure that this random number hasn't been added already
|
||||
if (added.contains(num)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// If necessary, record a false positive
|
||||
if (bf.contains(num)) {
|
||||
falsePositives++;
|
||||
}
|
||||
}
|
||||
double expectedFP = bf.falsePositiveProbability();
|
||||
double actualFP = (double) falsePositives / (double) addCount;
|
||||
System.out.println("Got " + falsePositives
|
||||
+ " false positives out of " + addCount + " added items, rate = "
|
||||
+ df.format(actualFP) + ", expected = "
|
||||
+ df.format(expectedFP));
|
||||
double ratio = actualFP/expectedFP;
|
||||
assertTrue(
|
||||
"Assert that the actual false positive rate doesn't deviate by more than 10% from what was predicted, ratio: "+ratio,
|
||||
ratio < 1.1);
|
||||
}
|
||||
}
|
||||
// Ensure that this random number hasn't been added already
|
||||
if (added.contains(num)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// If necessary, record a false positive
|
||||
if (bf.contains(num)) {
|
||||
falsePositives++;
|
||||
}
|
||||
}
|
||||
double expectedFP = bf.falsePositiveProbability();
|
||||
double actualFP = (double) falsePositives / (double) addCount;
|
||||
System.out.println("Got " + falsePositives
|
||||
+ " false positives out of " + addCount + " added items, rate = "
|
||||
+ df.format(actualFP) + ", expected = "
|
||||
+ df.format(expectedFP));
|
||||
double ratio = actualFP/expectedFP;
|
||||
assertTrue(
|
||||
"Assert that the actual false positive rate doesn't deviate by more than 10% from what was predicted, ratio: "+ratio,
|
||||
ratio < 1.1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,20 +30,20 @@ import java.io.InputStreamReader;
|
|||
|
||||
|
||||
public class ConsoleTest {
|
||||
public static void main(String[] args) throws IOException{
|
||||
Console terminal = new Console("Console Test");
|
||||
terminal.enableTray(true);
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
|
||||
public static void main(String[] args) throws IOException{
|
||||
Console terminal = new Console("Console Test");
|
||||
terminal.enableTray(true);
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
|
||||
|
||||
while(true){
|
||||
System.out.println("hello= "+in.readLine());
|
||||
for(int i=0; i<2 ;i++){
|
||||
System.out.println(i+"Hello World!!!sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss");
|
||||
System.err.println(i+"Hello World!!!sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss");
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
} catch (InterruptedException e) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
while(true){
|
||||
System.out.println("hello= "+in.readLine());
|
||||
for(int i=0; i<2 ;i++){
|
||||
System.out.println(i+"Hello World!!!sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss");
|
||||
System.err.println(i+"Hello World!!!sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss");
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
} catch (InterruptedException e) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue