Introducing the BaseApiTest class and making some test classes extend it
This commit is contained in:
parent
c9c33566fa
commit
a848c66fb9
3 changed files with 115 additions and 22 deletions
|
@ -0,0 +1,33 @@
|
|||
package de.bitsharesmunich.graphenej.api;
|
||||
|
||||
import com.neovisionaries.ws.client.WebSocket;
|
||||
import com.neovisionaries.ws.client.WebSocketFactory;
|
||||
|
||||
import org.junit.Before;
|
||||
|
||||
import javax.net.ssl.SSLContext;
|
||||
|
||||
import de.bitsharesmunich.graphenej.test.NaiveSSLContext;
|
||||
|
||||
/**
|
||||
* Created by nelson on 4/14/17.
|
||||
*/
|
||||
|
||||
public class BaseApiTest {
|
||||
protected String BLOCK_PAY_DE = System.getenv("BLOCKPAY_DE");
|
||||
|
||||
protected SSLContext context;
|
||||
protected WebSocket mWebSocket;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
context = NaiveSSLContext.getInstance("TLS");
|
||||
WebSocketFactory factory = new WebSocketFactory();
|
||||
|
||||
// Set the custom SSL context.
|
||||
factory.setSSLContext(context);
|
||||
|
||||
mWebSocket = factory.createSocket(BLOCK_PAY_DE);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,81 @@
|
|||
package de.bitsharesmunich.graphenej.api;
|
||||
|
||||
import com.neovisionaries.ws.client.WebSocketException;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import de.bitsharesmunich.graphenej.Address;
|
||||
import de.bitsharesmunich.graphenej.UserAccount;
|
||||
import de.bitsharesmunich.graphenej.errors.MalformedAddressException;
|
||||
import de.bitsharesmunich.graphenej.interfaces.WitnessResponseListener;
|
||||
import de.bitsharesmunich.graphenej.models.BaseResponse;
|
||||
import de.bitsharesmunich.graphenej.models.WitnessResponse;
|
||||
|
||||
/**
|
||||
* Created by nelson on 4/14/17.
|
||||
*/
|
||||
public class GetKeyReferencesTest extends BaseApiTest {
|
||||
|
||||
private String[] publicKeys = new String[] {
|
||||
"BTS8DuGHXpHYedq7qhT65BEEdQPvLT8nxZ862Hf8NgvSZUMuwUFkn",
|
||||
"BTS53ehf9Qoeg9o4E1KuxdZRXCVg3Z9ApbEDHVdQhERDJDEFkPkGs"
|
||||
};
|
||||
|
||||
@Test
|
||||
public void testGetKeyReferences(){
|
||||
ArrayList<Address> addresses = new ArrayList<>();
|
||||
for(String addr : publicKeys){
|
||||
try {
|
||||
Address address = new Address(addr);
|
||||
addresses.add(address);
|
||||
} catch (MalformedAddressException e) {
|
||||
System.out.println("MalformedAddressException. Msg: "+e.getMessage());
|
||||
}
|
||||
}
|
||||
mWebSocket.addListener(new GetKeyReferences(addresses, new WitnessResponseListener() {
|
||||
@Override
|
||||
public void onSuccess(WitnessResponse response) {
|
||||
System.out.println("onSuccess");
|
||||
int counter = 0;
|
||||
List<List<UserAccount>> accountListList = (List<List<UserAccount>>) response.result;
|
||||
for(List<UserAccount> accountList : accountListList){
|
||||
for(UserAccount userAccount : accountList){
|
||||
System.out.println("User account: "+userAccount.getObjectId());
|
||||
}
|
||||
if(accountList.size() > 1){
|
||||
System.out.println("Key with address: "+publicKeys[counter]+" controls more than one role in account: "+accountList.get(0).getObjectId());
|
||||
}else if(accountList.size() == 1){
|
||||
System.out.println("Key with address: "+publicKeys[counter]+" controls just one role in account: "+accountList.get(0).getObjectId());
|
||||
}
|
||||
counter++;
|
||||
}
|
||||
synchronized (GetKeyReferencesTest.this){
|
||||
GetKeyReferencesTest.this.notifyAll();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(BaseResponse.Error error) {
|
||||
System.out.println("onError. Msg: "+error.message);
|
||||
|
||||
synchronized (GetKeyReferencesTest.this){
|
||||
GetKeyReferencesTest.this.notifyAll();
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
||||
try{
|
||||
mWebSocket.connect();
|
||||
synchronized (this){
|
||||
wait();
|
||||
}
|
||||
} catch (WebSocketException e) {
|
||||
System.out.println("WebSocketException. Msg: " + e.getMessage());
|
||||
} catch (InterruptedException e) {
|
||||
System.out.println("InterruptedException. Msg: "+e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,19 +1,14 @@
|
|||
package de.bitsharesmunich.graphenej.api;
|
||||
|
||||
import com.google.common.primitives.UnsignedLong;
|
||||
import com.neovisionaries.ws.client.WebSocket;
|
||||
import com.neovisionaries.ws.client.WebSocketException;
|
||||
import com.neovisionaries.ws.client.WebSocketFactory;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.net.ssl.SSLContext;
|
||||
|
||||
import de.bitsharesmunich.graphenej.Asset;
|
||||
import de.bitsharesmunich.graphenej.AssetAmount;
|
||||
import de.bitsharesmunich.graphenej.Converter;
|
||||
|
@ -24,33 +19,17 @@ import de.bitsharesmunich.graphenej.interfaces.WitnessResponseListener;
|
|||
import de.bitsharesmunich.graphenej.models.BaseResponse;
|
||||
import de.bitsharesmunich.graphenej.models.WitnessResponse;
|
||||
import de.bitsharesmunich.graphenej.operations.LimitOrderCreateOperation;
|
||||
import de.bitsharesmunich.graphenej.test.NaiveSSLContext;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
|
||||
/**
|
||||
* Created by nelson on 3/24/17.
|
||||
*/
|
||||
public class GetLimitOrdersTest {
|
||||
private String BLOCK_PAY_DE = System.getenv("BLOCKPAY_DE");
|
||||
public class GetLimitOrdersTest extends BaseApiTest {
|
||||
private UserAccount seller = new UserAccount("1.2.143563");
|
||||
private final Asset base = new Asset("1.3.121", "USD", 4);
|
||||
private final Asset quote = new Asset("1.3.0", "BTS", 5);
|
||||
|
||||
private SSLContext context;
|
||||
private WebSocket mWebSocket;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
context = NaiveSSLContext.getInstance("TLS");
|
||||
WebSocketFactory factory = new WebSocketFactory();
|
||||
|
||||
// Set the custom SSL context.
|
||||
factory.setSSLContext(context);
|
||||
|
||||
mWebSocket = factory.createSocket(BLOCK_PAY_DE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetLimitOrders(){
|
||||
try {
|
||||
|
|
Loading…
Reference in a new issue