Skip to content

Commit 8623883

Browse files
author
[a561842] Hubert Marteau
committed
First step to JUnit tests
1 parent 7499df7 commit 8623883

File tree

3 files changed

+108
-146
lines changed

3 files changed

+108
-146
lines changed

pom.xml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>MultiChainJavaAPI</groupId>
55
<artifactId>MultiChainJavaAPI</artifactId>
6-
<version>0.4.0-SNAPSHOT</version>
6+
<version>0.4.1-SNAPSHOT</version>
77

88
<properties>
99
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
@@ -55,5 +55,12 @@
5555
<artifactId>commons-collections4</artifactId>
5656
<version>${commons-collections4.version}</version>
5757
</dependency>
58+
59+
<dependency>
60+
<groupId>junit</groupId>
61+
<artifactId>junit</artifactId>
62+
<version>4.12</version>
63+
<scope>test</scope>
64+
</dependency>
5865
</dependencies>
5966
</project>
Lines changed: 92 additions & 145 deletions
Original file line numberDiff line numberDiff line change
@@ -1,145 +1,92 @@
1-
/*
2-
* Copyright (C) 2017 Worldline, Inc.
3-
*
4-
* MultiChainJavaAPI code distributed under the GPLv3 license, see COPYING file.
5-
* https://github.com/SimplyUb/MultiChainJavaAPI/blob/master/LICENSE
6-
*
7-
*/
8-
package multichain.command;
9-
10-
import java.util.List;
11-
12-
import multichain.command.MultiChainCommand;
13-
import multichain.command.MultichainException;
14-
import multichain.object.Address;
15-
16-
/**
17-
* @author Ub - H. MARTEAU
18-
* @version 3.2
19-
*/
20-
public class AddressCommandTest {
21-
static MultiChainCommand multiChainCommand;
22-
23-
/**
24-
*
25-
*/
26-
public AddressCommandTest() {
27-
// TODO Auto-generated constructor stub
28-
}
29-
30-
private static void testgetAddresses() {
31-
List<String> result = null;
32-
List<Address> resultAddress = null;
33-
try {
34-
result = multiChainCommand.getAddressCommand().getAddresses();
35-
} catch (MultichainException e) {
36-
// TODO Auto-generated catch block
37-
e.printStackTrace();
38-
}
39-
if (result == null || result.size() == 0) {
40-
System.err.println("testgetAddresses - result list is empty");
41-
} else {
42-
System.out.println("testgetAddresses - Result :");
43-
for (String ad : result) {
44-
System.out.println(ad);
45-
}
46-
}
47-
System.out.println("");
48-
System.out.println("");
49-
try {
50-
resultAddress = multiChainCommand.getAddressCommand().getAddressesList();
51-
} catch (MultichainException e) {
52-
// TODO Auto-generated catch block
53-
e.printStackTrace();
54-
}
55-
if (resultAddress == null || resultAddress.size() == 0) {
56-
System.err.println("testgetAddressesList - result list is empty");
57-
} else {
58-
System.out.println("testgetAddressesList - Result :");
59-
for (Address ad : resultAddress) {
60-
System.out.println(ad.toString());
61-
}
62-
}
63-
System.out.println("");
64-
System.out.println("");
65-
}
66-
67-
private static void testvalidateAddress() {
68-
List<String> resultAddresses = null;
69-
Address result = null;
70-
try {
71-
resultAddresses = multiChainCommand.getAddressCommand().getAddresses();
72-
if (resultAddresses != null && resultAddresses.size() != 0) {
73-
for (String addressString : resultAddresses) {
74-
result = multiChainCommand.getAddressCommand().validateAddress(addressString);
75-
System.out.println("testvalidateAddress - result for address " + addressString + " :");
76-
System.out.println(result);
77-
78-
if (result == null || result.getAddress() == null || "".equals(result.getAddress())) {
79-
System.err.println("testvalidateAddress - result is not correct");
80-
}
81-
System.out.println("");
82-
}
83-
} else {
84-
System.err.println("testgetAddresses - result list is empty");
85-
}
86-
} catch (MultichainException e) {
87-
// TODO Auto-generated catch block
88-
e.printStackTrace();
89-
}
90-
}
91-
92-
private static void testgetNewAddress() {
93-
String resultAddress = "";
94-
Address result = null;
95-
96-
System.out.println("testgetNewAddress");
97-
try {
98-
resultAddress = multiChainCommand.getAddressCommand().getNewAddress();
99-
if (resultAddress != null && !"".equals(resultAddress)) {
100-
System.out.println(" getNewAddress :");
101-
System.out.println(resultAddress);
102-
} else {
103-
System.err.println("getNewAddress - result is empty");
104-
}
105-
System.out.println();
106-
System.out.println();
107-
108-
result = multiChainCommand.getAddressCommand().getNewAddressFilled();
109-
if (result != null && result.getAddress() != null && !"".equals(result.getAddress())) {
110-
System.out.println(" getNewAddressFilled :");
111-
System.out.println(result);
112-
} else {
113-
System.err.println("getNewAddress - result is empty");
114-
}
115-
System.out.println();
116-
System.out.println();
117-
118-
} catch (MultichainException e) {
119-
// TODO Auto-generated catch block
120-
e.printStackTrace();
121-
}
122-
}
123-
124-
/**
125-
* @param args
126-
*/
127-
public static void main(String[] args) {
128-
System.out.println("--- Start of AddressCommandTest ---");
129-
130-
// BlockChain TestCommand has to be created and started before
131-
multiChainCommand = new MultiChainCommand("localhost", "6824", "multichainrpc",
132-
"73oYQWzx45hossFPPWUgicpLvHhsD8PempYxnSF6bnY9");
133-
134-
testgetAddresses();
135-
testvalidateAddress();
136-
137-
System.out.println();
138-
System.out.println();
139-
140-
testgetNewAddress();
141-
142-
System.out.println("--- End of AddressCommandTest ---");
143-
}
144-
145-
}
1+
package multichain.command;
2+
3+
import java.util.List;
4+
5+
import org.junit.Test;
6+
7+
import junit.framework.TestCase;
8+
import multichain.object.Address;
9+
10+
public class AddressCommandTest extends TestCase {
11+
12+
@Test
13+
public void testgetAddresses() {
14+
MultiChainCommand multiChainCommand = new MultiChainCommand(TestConst.MULTICHAIN_SERVER_IP,
15+
TestConst.MULTICHAIN_SERVER_PORT, TestConst.MULTICHAIN_SERVER_LOGIN, TestConst.MULTICHAIN_SERVER_PWD);
16+
17+
List<String> result = null;
18+
List<Address> resultAddress = null;
19+
try {
20+
result = multiChainCommand.getAddressCommand().getAddresses();
21+
} catch (MultichainException e) {
22+
// TODO Auto-generated catch block
23+
e.printStackTrace();
24+
}
25+
26+
assertNotNull(result);
27+
assertFalse(result.size() == 0);
28+
29+
try {
30+
resultAddress = multiChainCommand.getAddressCommand().getAddressesList();
31+
} catch (MultichainException e) {
32+
// TODO Auto-generated catch block
33+
e.printStackTrace();
34+
}
35+
36+
assertNotNull(resultAddress);
37+
assertFalse(resultAddress.size() == 0);
38+
}
39+
40+
@Test
41+
public void testvalidateAddress() {
42+
MultiChainCommand multiChainCommand = new MultiChainCommand(TestConst.MULTICHAIN_SERVER_IP,
43+
TestConst.MULTICHAIN_SERVER_PORT, TestConst.MULTICHAIN_SERVER_LOGIN, TestConst.MULTICHAIN_SERVER_PWD);
44+
45+
List<String> resultAddresses = null;
46+
Address result = null;
47+
try {
48+
resultAddresses = multiChainCommand.getAddressCommand().getAddresses();
49+
50+
assertNotNull(resultAddresses);
51+
assertFalse(resultAddresses.size() == 0);
52+
53+
for (String addressString : resultAddresses) {
54+
result = multiChainCommand.getAddressCommand().validateAddress(addressString);
55+
56+
assertNotNull(result);
57+
assertNotNull(result.getAddress());
58+
assertNotSame("", result.getAddress());
59+
}
60+
} catch (MultichainException e) {
61+
// TODO Auto-generated catch block
62+
e.printStackTrace();
63+
}
64+
}
65+
66+
@Test
67+
public void testgetNewAddress() {
68+
MultiChainCommand multiChainCommand = new MultiChainCommand(TestConst.MULTICHAIN_SERVER_IP,
69+
TestConst.MULTICHAIN_SERVER_PORT, TestConst.MULTICHAIN_SERVER_LOGIN, TestConst.MULTICHAIN_SERVER_PWD);
70+
71+
String resultAddress = "";
72+
Address result = null;
73+
74+
try {
75+
resultAddress = multiChainCommand.getAddressCommand().getNewAddress();
76+
77+
assertNotNull(resultAddress);
78+
assertNotSame("", resultAddress);
79+
80+
result = multiChainCommand.getAddressCommand().getNewAddressFilled();
81+
82+
assertNotNull(result);
83+
assertNotNull(result.getAddress());
84+
assertNotSame("", result.getAddress());
85+
86+
} catch (MultichainException e) {
87+
// TODO Auto-generated catch block
88+
e.printStackTrace();
89+
}
90+
}
91+
92+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package multichain.command;
2+
3+
public class TestConst {
4+
public static String MULTICHAIN_SERVER_IP = "localhost";
5+
public static String MULTICHAIN_SERVER_PORT = "6824";
6+
public static String MULTICHAIN_SERVER_LOGIN = "multichainrpc";
7+
public static String MULTICHAIN_SERVER_PWD = "73oYQWzx45hossFPPWUgicpLvHhsD8PempYxnSF6bnY9";
8+
}

0 commit comments

Comments
 (0)