Skip to content

Commit

Permalink
Merge pull request #11 from xdjiang/master
Browse files Browse the repository at this point in the history
更新接口,修复单元测试问题
  • Loading branch information
xdjiang authored Apr 8, 2021
2 parents 73c2c5a + ee441e1 commit a61adb8
Show file tree
Hide file tree
Showing 9 changed files with 13 additions and 74 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
language: java

sudo: false
jdk:
- openjdk8

script:
- cd rpc
Expand Down
4 changes: 2 additions & 2 deletions rpc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
<modelVersion>4.0.0</modelVersion>

<groupId>com.jccdex</groupId>
<artifactId>rpc</artifactId>
<artifactId>JccRPC</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>rpc</name>
<name>JccRPC</name>
<url>http://maven.apache.org</url>

<properties>
Expand Down
2 changes: 0 additions & 2 deletions rpc/src/main/java/com/jccdex/rpc/api/Info.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,4 @@ public interface Info {

void requestHistory(String base, String counter, String type, String time, JCallback callBack);

void requestTickerFromCMC(String token, String currency, JCallback callBack);

}
34 changes: 0 additions & 34 deletions rpc/src/main/java/com/jccdex/rpc/api/JccdexInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -222,38 +222,4 @@ public void requestHistory(@NotNull String base, @NotNull String counter, @NotNu
}
}

/**
* request token info from coinmarketdata
*
* @param token
* @param currency
* @param callBack
*/
@Override
public void requestTickerFromCMC(@NotNull String token, @NotNull String currency, @NotNull JCallback callBack) {
String url = mBaseUrl.getUrl() + "/" + token.toLowerCase() + "_" + currency.toLowerCase() + ".json";
String t = String.valueOf(new Date().getTime());
final Request.Builder reBuild = new Request.Builder();
HttpUrl.Builder urlBuilder = HttpUrl.parse(url).newBuilder();
urlBuilder.addQueryParameter("t", t);
reBuild.url(urlBuilder.build());
Request request = reBuild.build();
try {
Response response = okHttpClient.newCall(request).execute();
if (CommUtils.isSuccessful(response.code())) {
ResponseBody body = response.body();
String res = body.string();
ObjectMapper mapper = new ObjectMapper();
JsonNode actualObj = mapper.readTree(res);
String code = actualObj.get("code").asText();
callBack.onResponse(code, res);
body.close();
} else {
callBack.onFail(new Exception(CommUtils.formatExceptionMessage(response)));
}
} catch (IOException e) {
callBack.onFail(e);
}
}

}
2 changes: 1 addition & 1 deletion rpc/src/main/java/com/jccdex/rpc/config/JConstant.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public class JConstant {
* <P>
* {@value}
*/
public static final String JC_REQUEST_CONFIG_ROUTE = "/static/config/jc_config.json";
public static final String JC_REQUEST_CONFIG_ROUTE = "/static/config/jc_hosts.json";

/**
* Explore API route.
Expand Down
5 changes: 3 additions & 2 deletions rpc/src/test/java/com/jccdex/rpc/api/JccConfigTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

public class JccConfigTest {

public final String host = "192.168.66.253";
public JccdexUrl jccUrl = new JccdexUrl(host, false);
public final String host = "uploadletsdex.swtc.top";
public JccdexUrl jccUrl = new JccdexUrl(host, true);
// public final String host = "ektjsbdyfg.weidex.vip";
// public JccdexUrl jccUrl = new JccdexUrl(host, true);

Expand All @@ -22,6 +22,7 @@ public void test() {
mockCallBack = Mockito.mock(JCallback.class);
config.requestConfig(mockCallBack);
Mockito.verify(mockCallBack).onResponse(Mockito.anyString(), Mockito.anyString());

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
public class JccdexExchangeTest {
// public final String host = "192.168.66.253";
// public JccdexUrl jccUrl = new JccdexUrl(host, false);
public final String host = "ejia348ffbda04.jccdex.cn";
public final String host = "eji39bdbd155a03.swtc.top";
public JccdexUrl jccUrl = new JccdexUrl(host, true);

JccdexExchange exchange = JccdexExchange.getInstance();
Expand Down
36 changes: 4 additions & 32 deletions rpc/src/test/java/com/jccdex/rpc/api/JccdexInfoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@

public class JccdexInfoTest {

public final String host = "192.168.66.253";
public JccdexUrl jccUrl = new JccdexUrl(host, false);
// public final String host = "ia111ecfd37.jccdex.cn";
// public JccdexUrl jccUrl = new JccdexUrl(host, true);
// public final String host = "192.168.66.253";
// public JccdexUrl jccUrl = new JccdexUrl(host, false);
public final String host = "iji41bdbd42011.swtc.top";
public JccdexUrl jccUrl = new JccdexUrl(host, true);

public JccdexInfo info = JccdexInfo.getInstance();
public JCallback mockCallBack;
Expand All @@ -32,8 +32,6 @@ public void testReuestAll() {
Mockito.verify(mockInfo).requestKline("swt", "cnt", "hour", mockCallBack);
mockInfo.requestHistory("swt", "cnt", "newest", "1111", mockCallBack);
Mockito.verify(mockInfo).requestHistory("swt", "cnt", "newest", "1111", mockCallBack);
mockInfo.requestTickerFromCMC("eth", "cny", mockCallBack);
Mockito.verify(mockInfo).requestTickerFromCMC("eth", "cny", mockCallBack);
}

@Test
Expand Down Expand Up @@ -201,30 +199,4 @@ public void testReuestHistory() throws ParseException {
info.requestHistory("", "cnt", "", unixtime, mockCallBack);
Mockito.verify(mockCallBack).onFail(Mockito.any(Exception.class));
}

@Test
public void testReuestTickerFromCMC() {
String host = "weidex.vip";
JccdexUrl jccUrl = new JccdexUrl(host, true);
info.setmBaseUrl(jccUrl);
mockCallBack = Mockito.mock(JCallback.class);
info.requestTickerFromCMC("eth", "cny", mockCallBack);
Mockito.verify(mockCallBack).onResponse(Mockito.anyString(), Mockito.anyString());
mockCallBack = Mockito.mock(JCallback.class);
info.requestTickerFromCMC("eth", "cnt", mockCallBack);
Mockito.verify(mockCallBack).onFail(Mockito.any(Exception.class));
mockCallBack = Mockito.mock(JCallback.class);
info.requestTickerFromCMC("", "cny", mockCallBack);
Mockito.verify(mockCallBack).onFail(Mockito.any(Exception.class));
mockCallBack = Mockito.mock(JCallback.class);
info.requestTickerFromCMC("eth", "", mockCallBack);
Mockito.verify(mockCallBack).onFail(Mockito.any(Exception.class));
mockCallBack = Mockito.mock(JCallback.class);
info.requestTickerFromCMC("", "", mockCallBack);
Mockito.verify(mockCallBack).onFail(Mockito.any(Exception.class));
mockCallBack = Mockito.mock(JCallback.class);
info.setmBaseUrl(new JccdexUrl("11", true));
info.requestTickerFromCMC("eth", "cny", mockCallBack);
Mockito.verify(mockCallBack).onFail(Mockito.any(Exception.class));
}
}
Binary file added sdk/JccRPC-0.0.1.jar
Binary file not shown.

0 comments on commit a61adb8

Please sign in to comment.