use of si.mazi.rescu.RestMethodMetadata in project XChange by knowm.
the class ApiSignatureTest method testSignature.
@Test
public void testSignature() {
FCoinDigest digest = FCoinDigest.createInstance("3600d0a74aa3410fb3b1996cca2419c8");
FCoinOrder order = new FCoinOrder("btcusdt", FCoinSide.buy, FCoinType.limit, new BigDecimal("100.0"), new BigDecimal("100.0"));
RequestWriterResolver writerResolver = new RequestWriterResolver();
writerResolver.addWriter("application/json", new JacksonRequestWriter(new ObjectMapper()));
HeaderParam headerParamAnn = new HeaderParam() {
@Override
public Class<? extends Annotation> annotationType() {
return HeaderParam.class;
}
@Override
public String value() {
return "FC-ACCESS-TIMESTAMP";
}
};
String signature = digest.digestParams(RestInvocation.create(writerResolver, new RestMethodMetadata(null, HttpMethod.POST, "https://api.fcoin.com/", "v2", "orders", null, "application/json", "application/json", null, new HashMap<>(), new Annotation[][] { { headerParamAnn }, {} }), new Object[] { "1523069544359", order }, null));
Assertions.assertThat(signature).isEqualTo("DeP6oftldIrys06uq3B7Lkh3a0U=");
}
use of si.mazi.rescu.RestMethodMetadata in project rescu by mmazi.
the class JacksonRequestWriterTest method testWriteBody.
/**
* Test of writeBody method, of class JacksonRequestWriter.
*/
@Test
public void testWriteBody() {
JacksonRequestWriter writer = new JacksonRequestWriter(new DefaultJacksonObjectMapperFactory().createObjectMapper());
DummyAccountInfo dummyAccountInfo = new DummyAccountInfo("mm", "USD", 3);
RestInvocation invocation = RestInvocation.create(null, new RestMethodMetadata(String.class, GET, null, null, null, RuntimeException.class, APPLICATION_JSON, APPLICATION_JSON, null, new HashMap<>(), new Annotation[][] { {} }), new Object[] { dummyAccountInfo }, null);
String json = writer.writeBody(invocation);
assertEquals(json, "{\"username\":\"mm\",\"currency\":\"USD\",\"amount_int\":3}");
}
use of si.mazi.rescu.RestMethodMetadata in project XChange by knowm.
the class BleutradeDigestTest method shouldEncodeRestInvocation.
@Test
public void shouldEncodeRestInvocation() throws Exception {
// given
RequestWriterResolver requestWriterResolver = new RequestWriterResolver();
requestWriterResolver.addWriter(TEXT_PLAIN, new ToStringRequestWriter());
RestInvocation invocation = RestInvocation.create(requestWriterResolver, new RestMethodMetadata(null, null, "rest body", null, null, null, TEXT_PLAIN, TEXT_PLAIN, null, new HashMap<>(), new Annotation[][] {}), new Object[] {}, null);
String expected = "6372f349eea659b26f5e01bc76e1485de744a1894d5e036b98eca724a8104719ea8767518286863d1becd0a1313ad5e7e507749f7cdb98a4dee92fec055643c4";
// when
String encoded = bleutradeDigest.digestParams(invocation);
// then
assertThat(encoded).isEqualTo(expected);
}
use of si.mazi.rescu.RestMethodMetadata in project XChange by knowm.
the class PoloniexOrderTest method sellRejectTest.
@Test(expected = PoloniexException.class)
public void sellRejectTest() throws Exception {
InvocationResult invocationResult = new InvocationResult("{\"error\":\"Not enough LTC.\"}", 200);
Method apiMethod = PoloniexAuthenticated.class.getDeclaredMethod("sell", String.class, ParamsDigest.class, SynchronizedValueFactory.class, String.class, String.class, String.class, Integer.class, Integer.class, Integer.class);
RestMethodMetadata data = RestMethodMetadata.create(apiMethod, "", "");
try {
new JacksonResponseReader(new DefaultJacksonObjectMapperFactory().createObjectMapper(), false).read(invocationResult, data);
} catch (PoloniexException e) {
Assert.assertTrue(e.getMessage().startsWith("Not enough LTC."));
throw e;
}
}
use of si.mazi.rescu.RestMethodMetadata in project XChange by knowm.
the class PoloniexOrderTest method moveOrderRejectTest.
@Test(expected = PoloniexException.class)
public void moveOrderRejectTest() throws Exception {
InvocationResult invocationResult = new InvocationResult("{\"success\":0,\"error\":\"Not enough LTC.\"}", 200);
Method apiMethod = PoloniexAuthenticated.class.getDeclaredMethod("moveOrder", String.class, ParamsDigest.class, SynchronizedValueFactory.class, String.class, String.class, String.class, Integer.class, Integer.class);
RestMethodMetadata data = RestMethodMetadata.create(apiMethod, "", "");
try {
new JacksonResponseReader(new DefaultJacksonObjectMapperFactory().createObjectMapper(), false).read(invocationResult, data);
} catch (PoloniexException e) {
Assert.assertTrue(e.getMessage().startsWith("Not enough LTC."));
throw e;
}
}
Aggregations