Search in sources :

Example 1 with RestMethodMetadata

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=");
}
Also used : HeaderParam(javax.ws.rs.HeaderParam) FCoinDigest(org.knowm.xchange.fcoin.service.FCoinDigest) RequestWriterResolver(si.mazi.rescu.RequestWriterResolver) FCoinOrder(org.knowm.xchange.fcoin.dto.trade.FCoinOrder) BigDecimal(java.math.BigDecimal) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JacksonRequestWriter(si.mazi.rescu.serialization.jackson.JacksonRequestWriter) RestMethodMetadata(si.mazi.rescu.RestMethodMetadata) Test(org.junit.Test)

Example 2 with RestMethodMetadata

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}");
}
Also used : HashMap(java.util.HashMap) DummyAccountInfo(si.mazi.rescu.dto.DummyAccountInfo) RestInvocation(si.mazi.rescu.RestInvocation) Annotation(java.lang.annotation.Annotation) RestMethodMetadata(si.mazi.rescu.RestMethodMetadata) Test(org.testng.annotations.Test)

Example 3 with RestMethodMetadata

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);
}
Also used : RequestWriterResolver(si.mazi.rescu.RequestWriterResolver) HashMap(java.util.HashMap) RestInvocation(si.mazi.rescu.RestInvocation) ToStringRequestWriter(si.mazi.rescu.serialization.ToStringRequestWriter) Annotation(java.lang.annotation.Annotation) RestMethodMetadata(si.mazi.rescu.RestMethodMetadata) Test(org.junit.Test)

Example 4 with RestMethodMetadata

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;
    }
}
Also used : DefaultJacksonObjectMapperFactory(si.mazi.rescu.serialization.jackson.DefaultJacksonObjectMapperFactory) Method(java.lang.reflect.Method) InvocationResult(si.mazi.rescu.InvocationResult) JacksonResponseReader(si.mazi.rescu.serialization.jackson.JacksonResponseReader) PoloniexException(org.knowm.xchange.poloniex.dto.PoloniexException) RestMethodMetadata(si.mazi.rescu.RestMethodMetadata) Test(org.junit.Test)

Example 5 with RestMethodMetadata

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;
    }
}
Also used : DefaultJacksonObjectMapperFactory(si.mazi.rescu.serialization.jackson.DefaultJacksonObjectMapperFactory) Method(java.lang.reflect.Method) InvocationResult(si.mazi.rescu.InvocationResult) JacksonResponseReader(si.mazi.rescu.serialization.jackson.JacksonResponseReader) PoloniexException(org.knowm.xchange.poloniex.dto.PoloniexException) RestMethodMetadata(si.mazi.rescu.RestMethodMetadata) Test(org.junit.Test)

Aggregations

RestMethodMetadata (si.mazi.rescu.RestMethodMetadata)7 Test (org.junit.Test)6 Method (java.lang.reflect.Method)4 PoloniexException (org.knowm.xchange.poloniex.dto.PoloniexException)4 InvocationResult (si.mazi.rescu.InvocationResult)4 DefaultJacksonObjectMapperFactory (si.mazi.rescu.serialization.jackson.DefaultJacksonObjectMapperFactory)4 JacksonResponseReader (si.mazi.rescu.serialization.jackson.JacksonResponseReader)4 Annotation (java.lang.annotation.Annotation)2 HashMap (java.util.HashMap)2 RequestWriterResolver (si.mazi.rescu.RequestWriterResolver)2 RestInvocation (si.mazi.rescu.RestInvocation)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 BigDecimal (java.math.BigDecimal)1 HeaderParam (javax.ws.rs.HeaderParam)1 FCoinOrder (org.knowm.xchange.fcoin.dto.trade.FCoinOrder)1 FCoinDigest (org.knowm.xchange.fcoin.service.FCoinDigest)1 Test (org.testng.annotations.Test)1 DummyAccountInfo (si.mazi.rescu.dto.DummyAccountInfo)1 ToStringRequestWriter (si.mazi.rescu.serialization.ToStringRequestWriter)1 JacksonRequestWriter (si.mazi.rescu.serialization.jackson.JacksonRequestWriter)1