Some refactoring and added some JUnit tests
This commit is contained in:
parent
d107cd504c
commit
24c4fac26d
13 changed files with 168 additions and 100 deletions
41
test/zutil/net/torrent/TorrentMetainfoTest.java
Executable file
41
test/zutil/net/torrent/TorrentMetainfoTest.java
Executable file
|
|
@ -0,0 +1,41 @@
|
|||
package zutil.net.torrent;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.text.ParseException;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Created by Ziver on 2016-09-27.
|
||||
*/
|
||||
public class TorrentMetainfoTest {
|
||||
|
||||
|
||||
@Test
|
||||
public void decode() throws ParseException {
|
||||
TorrentMetainfo tmp = new TorrentMetainfo(
|
||||
"d8:announce39:http://torrent.ubuntu.com:6969/announce13:announce-listll" +
|
||||
"39:http://torrent.ubuntu.com:6969/announceel44:http://ipv6.torrent.ubuntu.com:6969/announceee" +
|
||||
"7:comment29:Ubuntu CD releases.ubuntu.com13:creation datei1469103218e4:infod" +
|
||||
"6:lengthi1513308160e4:name32:ubuntu-16.04.1-desktop-amd64.iso12:piece lengthi524288e" +
|
||||
"6:pieces60:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaee");
|
||||
|
||||
assertEquals("http://torrent.ubuntu.com:6969/announce", tmp.getAnnounce());
|
||||
assertArrayEquals(new String[]{
|
||||
"http://torrent.ubuntu.com:6969/announce",
|
||||
"http://ipv6.torrent.ubuntu.com:6969/announce"},
|
||||
tmp.getAnnounceList().toArray());
|
||||
assertEquals("Ubuntu CD releases.ubuntu.com", tmp.getComment());
|
||||
assertEquals(1469103218, tmp.getCreationDate());
|
||||
assertEquals(1513308160, tmp.getSize());
|
||||
assertEquals("ubuntu-16.04.1-desktop-amd64.iso", tmp.getName());
|
||||
assertEquals(1, tmp.getFileList().size());
|
||||
assertEquals("ubuntu-16.04.1-desktop-amd64.iso", tmp.getFileList().get(0).getFilename());
|
||||
assertEquals(524288, tmp.getPieceLength());
|
||||
assertEquals(3, tmp.getPieceHashes().size());
|
||||
assertEquals("aaaaaaaaaaaaaaaaaaaa", tmp.getPieceHashes().get(0));
|
||||
assertEquals("aaaaaaaaaaaaaaaaaaaa", tmp.getPieceHashes().get(1));
|
||||
assertEquals("aaaaaaaaaaaaaaaaaaaa", tmp.getPieceHashes().get(2));
|
||||
}
|
||||
}
|
||||
49
test/zutil/net/ws/rest/RestHttpPageTest.java
Executable file
49
test/zutil/net/ws/rest/RestHttpPageTest.java
Executable file
|
|
@ -0,0 +1,49 @@
|
|||
package zutil.net.ws.rest;
|
||||
|
||||
import org.junit.Test;
|
||||
import zutil.net.ws.WSInterface;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Created by Ziver on 2016-09-27.
|
||||
*/
|
||||
public class RestHttpPageTest {
|
||||
|
||||
public static class TestClass implements WSInterface{
|
||||
public String hello(){
|
||||
return "hello world";
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void noInput() throws Throwable {
|
||||
RestHttpPage rest = new RestHttpPage(new TestClass());
|
||||
|
||||
HashMap<String,String> input = new HashMap<>();
|
||||
String output = rest.execute("hello", input);
|
||||
assertEquals("\"hello world\"\n", output);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public static class TestEchoClass implements WSInterface{
|
||||
public String echo(@WSParamName("input") String input){
|
||||
return "echo: "+input;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void oneInput() throws Throwable {
|
||||
RestHttpPage rest = new RestHttpPage(new TestEchoClass());
|
||||
|
||||
HashMap<String,String> input = new HashMap<>();
|
||||
input.put("input", "test input");
|
||||
String output = rest.execute("echo", input);
|
||||
assertEquals("\"echo: test input\"\n", output);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -38,10 +38,6 @@ import zutil.parser.wsdl.WSDLWriter;
|
|||
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 );
|
||||
|
||||
|
|
@ -84,7 +80,7 @@ public class SOAPTest {
|
|||
public static class SpecialReturnClass extends WSReturnObject{
|
||||
@WSValueName(value="otherValue1")
|
||||
public String param1 = "otherValue1";
|
||||
@WSValueName("otherValue2")
|
||||
@WSValueName("otherName2")
|
||||
public String param2 = "otherValue2";
|
||||
public byte[] b = new byte[]{0x12, 0x23};
|
||||
public InnerClass inner = new InnerClass();
|
||||
|
|
@ -147,7 +143,7 @@ public class SOAPTest {
|
|||
@WSParamDocumentation("void method documentation")
|
||||
public void voidMethod (){ }
|
||||
|
||||
@WSDisabled()
|
||||
@WSIgnore()
|
||||
public void disabledMethod(){ }
|
||||
protected void protectedMethod(){ }
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue