Changed folder structure of test classes and renamed some packages
This commit is contained in:
parent
ccd50ec104
commit
884c5d64c3
76 changed files with 5305 additions and 5375 deletions
41
test/zutil/net/ServerFindClientTest.java
Executable file
41
test/zutil/net/ServerFindClientTest.java
Executable file
|
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2015 Ziver Koc
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package zutil.net;
|
||||
|
||||
import zutil.net.ServerFindClient;
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
38
test/zutil/net/ServerFindServerTest.java
Executable file
38
test/zutil/net/ServerFindServerTest.java
Executable file
|
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2015 Ziver Koc
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package zutil.net;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
|
||||
public class ServerFindServerTest {
|
||||
public static void main(String[] args){
|
||||
try {
|
||||
new ServerFind(2000);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
102
test/zutil/net/http/HTTPGuessTheNumber.java
Executable file
102
test/zutil/net/http/HTTPGuessTheNumber.java
Executable file
|
|
@ -0,0 +1,102 @@
|
|||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2015 Ziver Koc
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package zutil.net.http;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
public class HTTPGuessTheNumber implements HttpPage{
|
||||
|
||||
public static void main(String[] args) throws IOException{
|
||||
//HttpServer server = new HttpServer("localhost", 443, FileFinder.find("keySSL"), "rootroot");//SSL
|
||||
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 {
|
||||
|
||||
out.enableBuffering(true);
|
||||
out.println("<html>");
|
||||
out.println("<H2>Welcome To The Number Guess Game!</H2>");
|
||||
|
||||
if(session.containsKey("random_nummber") && request.containsKey("guess") && !request.get("guess").isEmpty()){
|
||||
int guess = Integer.parseInt(request.get("guess"));
|
||||
int nummber = (Integer)session.get("random_nummber");
|
||||
try {
|
||||
if(guess == nummber){
|
||||
session.remove("random_nummber");
|
||||
out.println("You Guessed Right! Congrats!");
|
||||
out.println("</html>");
|
||||
return;
|
||||
}
|
||||
else if(guess > nummber){
|
||||
out.println("<b>To High</b><br>");
|
||||
if(Integer.parseInt(cookie.get("high")) > guess){
|
||||
out.setCookie("high", ""+guess);
|
||||
cookie.put("high", ""+guess);
|
||||
}
|
||||
}
|
||||
else{
|
||||
out.println("<b>To Low</b><br>");
|
||||
if(Integer.parseInt(cookie.get("low")) < guess){
|
||||
out.setCookie("low", ""+guess);
|
||||
cookie.put("low", ""+guess);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
else{
|
||||
session.put("random_nummber", (int)(Math.random()*99+1));
|
||||
try {
|
||||
out.setCookie("low", "0");
|
||||
out.setCookie("high", "100");
|
||||
cookie.put("low", "0");
|
||||
cookie.put("high", "100");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
out.println("<form method='post'>");
|
||||
out.println(cookie.get("low")+" < X < "+cookie.get("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: nummber="+session.get("random_nummber")+"</b><br>");
|
||||
out.println("</html>");
|
||||
}
|
||||
|
||||
}
|
||||
57
test/zutil/net/http/HTTPUploaderTest.java
Executable file
57
test/zutil/net/http/HTTPUploaderTest.java
Executable file
|
|
@ -0,0 +1,57 @@
|
|||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2015 Ziver Koc
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package zutil.net.http;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
public class HTTPUploaderTest implements HttpPage{
|
||||
|
||||
public static void main(String[] args) throws IOException{
|
||||
HttpServer server = new HttpServer(80);
|
||||
server.setDefaultPage(new HTTPUploaderTest());
|
||||
server.run();
|
||||
}
|
||||
|
||||
public void respond(HttpPrintStream out,
|
||||
HttpHeader client_info,
|
||||
Map<String, Object> session,
|
||||
Map<String, String> cookie,
|
||||
Map<String, String> request) throws IOException {
|
||||
|
||||
if(!session.containsKey("file1")){
|
||||
out.println("</html>" +
|
||||
" <form enctype='multipart/form-data' method='post'>" +
|
||||
" <p>Please specify a file, or a set of files:<br>" +
|
||||
" <input type='file' name='datafile' size='40'>" +
|
||||
" </p>" +
|
||||
" <input type='submit' value='Send'>" +
|
||||
" </form>" +
|
||||
"</html>");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
74
test/zutil/net/http/HttpURLTest.java
Executable file
74
test/zutil/net/http/HttpURLTest.java
Executable file
|
|
@ -0,0 +1,74 @@
|
|||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2015 Ziver Koc
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package zutil.net.http;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.allOf;
|
||||
import static org.hamcrest.CoreMatchers.containsString;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
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")));
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
59
test/zutil/net/nio/NetworkClientTest.java
Executable file
59
test/zutil/net/nio/NetworkClientTest.java
Executable file
|
|
@ -0,0 +1,59 @@
|
|||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2015 Ziver Koc
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package zutil.net.nio;
|
||||
|
||||
import zutil.net.nio.message.StringMessage;
|
||||
import zutil.net.nio.response.PrintRsp;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetAddress;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class NetworkClientTest {
|
||||
public static void main(String[] args) throws NoSuchAlgorithmException {
|
||||
try {
|
||||
int count = 0;
|
||||
long time = System.currentTimeMillis()+1000*60;
|
||||
NioClient client = new NioClient(InetAddress.getByName("localhost"), 6056);
|
||||
//client.setEncrypter(new Encrypter("lol", Encrypter.PASSPHRASE_DES_ALGO));
|
||||
while(time > System.currentTimeMillis()){
|
||||
PrintRsp handler = new PrintRsp();
|
||||
client.send(handler, new StringMessage("StringMessage: "+count));
|
||||
handler.waitForResponse();
|
||||
//try {Thread.sleep(100);} catch (InterruptedException e) {}
|
||||
//System.out.println("sending..");
|
||||
count++;
|
||||
}
|
||||
|
||||
System.out.println("Message Count 1m: "+count);
|
||||
System.out.println("Message Count 1s: "+count/60);
|
||||
System.exit(0);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
41
test/zutil/net/nio/NetworkServerTest.java
Executable file
41
test/zutil/net/nio/NetworkServerTest.java
Executable file
|
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2015 Ziver Koc
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package zutil.net.nio;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class NetworkServerTest {
|
||||
public static void main(String[] args) throws NoSuchAlgorithmException {
|
||||
try {
|
||||
NioServer server = new NioServer(6056);
|
||||
//server.setEncrypter(new Encrypter("lol", Encrypter.PASSPHRASE_DES_ALGO));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
52
test/zutil/net/ssdp/SSDPClientTest.java
Executable file
52
test/zutil/net/ssdp/SSDPClientTest.java
Executable file
|
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2015 Ziver Koc
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package zutil.net.ssdp;
|
||||
|
||||
import zutil.log.LogUtil;
|
||||
import zutil.net.ssdp.SSDPClient;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.logging.Level;
|
||||
|
||||
|
||||
/**
|
||||
* Created by Ziver on 2015-09-29.
|
||||
*/
|
||||
public class SSDPClientTest {
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
System.out.println(LogUtil.getCallingClass());
|
||||
LogUtil.setGlobalLevel(Level.FINEST);
|
||||
SSDPClient ssdp = new SSDPClient();
|
||||
ssdp.requestService("upnp:rootdevice");
|
||||
ssdp.start();
|
||||
|
||||
for(int i=0; true ;++i){
|
||||
while( i==ssdp.getServicesCount("upnp:rootdevice") ){ try{Thread.sleep(100);}catch(Exception e){} }
|
||||
System.out.println("************************" );
|
||||
System.out.println("" + ssdp.getServices("upnp:rootdevice").get(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
53
test/zutil/net/ssdp/SSDPServerTest.java
Executable file
53
test/zutil/net/ssdp/SSDPServerTest.java
Executable file
|
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2015 Ziver Koc
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package zutil.net.ssdp;
|
||||
|
||||
import zutil.log.LogUtil;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.logging.Level;
|
||||
|
||||
|
||||
/**
|
||||
* Created by Ziver on 2015-09-29.
|
||||
*/
|
||||
public class SSDPServerTest {
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
LogUtil.setGlobalLevel(Level.FINEST);
|
||||
|
||||
StandardSSDPInfo service = new StandardSSDPInfo();
|
||||
service.setLocation("nowhere");
|
||||
service.setST("zep:discover");
|
||||
service.setHeader("Alias", "Desktop");
|
||||
service.setHeader("PublicKey", "SuperDesktopKey");
|
||||
|
||||
|
||||
SSDPServer ssdp = new SSDPServer();
|
||||
ssdp.addService(service);
|
||||
ssdp.start();
|
||||
System.out.println("SSDP Server running");
|
||||
}
|
||||
}
|
||||
73
test/zutil/net/update/UpdateClientTest.java
Executable file
73
test/zutil/net/update/UpdateClientTest.java
Executable file
|
|
@ -0,0 +1,73 @@
|
|||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2015 Ziver Koc
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package zutil.net.update;
|
||||
|
||||
import zutil.ProgressListener;
|
||||
import zutil.log.CompactLogFormatter;
|
||||
import zutil.log.LogUtil;
|
||||
|
||||
import java.awt.*;
|
||||
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 void progressUpdate(UpdateClient source, FileInfo info, double percent) {
|
||||
System.out.println(info+": "+percent+"%");
|
||||
}
|
||||
}
|
||||
44
test/zutil/net/update/UpdateServerTest.java
Executable file
44
test/zutil/net/update/UpdateServerTest.java
Executable file
|
|
@ -0,0 +1,44 @@
|
|||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2015 Ziver Koc
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package zutil.net.update;
|
||||
|
||||
import zutil.log.CompactLogFormatter;
|
||||
import zutil.log.LogUtil;
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
63
test/zutil/net/upnp/UPnPServerTest.java
Executable file
63
test/zutil/net/upnp/UPnPServerTest.java
Executable file
|
|
@ -0,0 +1,63 @@
|
|||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2015 Ziver Koc
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package zutil.net.upnp;
|
||||
|
||||
import zutil.io.MultiPrintStream;
|
||||
import zutil.net.http.HttpServer;
|
||||
import zutil.net.ssdp.SSDPServer;
|
||||
import zutil.net.upnp.service.UPnPContentDirectory;
|
||||
import zutil.net.ws.WebServiceDef;
|
||||
import zutil.net.ws.soap.SOAPHttpPage;
|
||||
|
||||
import java.io.File;
|
||||
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");
|
||||
}
|
||||
}
|
||||
55
test/zutil/net/ws/soap/SOAPClientTest.java
Executable file
55
test/zutil/net/ws/soap/SOAPClientTest.java
Executable file
|
|
@ -0,0 +1,55 @@
|
|||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2015 Ziver Koc
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package zutil.net.ws.soap;
|
||||
|
||||
import zutil.log.CompactLogFormatter;
|
||||
import zutil.log.LogUtil;
|
||||
import zutil.net.ws.WSInterface;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
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();
|
||||
|
||||
}
|
||||
}
|
||||
157
test/zutil/net/ws/soap/SOAPTest.java
Executable file
157
test/zutil/net/ws/soap/SOAPTest.java
Executable file
|
|
@ -0,0 +1,157 @@
|
|||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2015 Ziver Koc
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package zutil.net.ws.soap;
|
||||
|
||||
import org.dom4j.Document;
|
||||
import org.dom4j.io.OutputFormat;
|
||||
import org.dom4j.io.XMLWriter;
|
||||
|
||||
import zutil.net.ws.WSInterface;
|
||||
import zutil.net.ws.WSInterface.WSNamespace;
|
||||
import zutil.net.ws.WSReturnObject;
|
||||
import zutil.net.ws.WebServiceDef;
|
||||
import zutil.parser.wsdl.WSDLWriter;
|
||||
|
||||
|
||||
// TODO: Convert to JUnit
|
||||
public class SOAPTest {
|
||||
/************************* TEST CASES ************************/
|
||||
public static void main(String[] args){
|
||||
new SOAPTest();
|
||||
}
|
||||
|
||||
public SOAPTest(){
|
||||
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" +
|
||||
|
||||
" <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 *********************" );
|
||||
|
||||
OutputFormat format = OutputFormat.createPrettyPrint();
|
||||
XMLWriter writer = new XMLWriter( System.out, format );
|
||||
writer.write( document );
|
||||
|
||||
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("otherValue2")
|
||||
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";
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
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");
|
||||
}
|
||||
|
||||
@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("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("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 (){ }
|
||||
|
||||
@WSDisabled()
|
||||
public void disabledMethod(){ }
|
||||
protected void protectedMethod(){ }
|
||||
|
||||
private void privateMethod(){ }
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue