Search in sources :

Example 16 with ForestJsonConverter

use of com.dtflys.forest.converter.json.ForestJsonConverter in project forest by dromara.

the class TestFastjsonConverter method testConfig.

@Test
public void testConfig() {
    ForestJsonConverter jsonConverter = forestConfiguration.getJsonConverter();
    assertThat(jsonConverter).isNotNull().isInstanceOf(ForestFastjsonConverter.class);
    ForestFastjsonConverter forestFastjsonConverter = (ForestFastjsonConverter) jsonConverter;
    assertThat(forestFastjsonConverter.getDateFormat()).isEqualTo("yyyy/MM/dd hh:mm:ss");
}
Also used : ForestFastjsonConverter(com.dtflys.forest.converter.json.ForestFastjsonConverter) ForestJsonConverter(com.dtflys.forest.converter.json.ForestJsonConverter) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 17 with ForestJsonConverter

use of com.dtflys.forest.converter.json.ForestJsonConverter in project forest by dromara.

the class TestGsonConverter method testConfig.

@Test
public void testConfig() {
    ForestJsonConverter jsonConverter = forestConfiguration.getJsonConverter();
    assertThat(jsonConverter).isNotNull().isInstanceOf(ForestGsonConverter.class);
    ForestGsonConverter forestGsonConverter = (ForestGsonConverter) jsonConverter;
    assertThat(forestGsonConverter.getDateFormat()).isEqualTo("yyyy/MM/dd hh:mm:ss");
}
Also used : ForestJsonConverter(com.dtflys.forest.converter.json.ForestJsonConverter) ForestGsonConverter(com.dtflys.forest.converter.json.ForestGsonConverter) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 18 with ForestJsonConverter

use of com.dtflys.forest.converter.json.ForestJsonConverter in project forest by dromara.

the class TestJacksonConverter method testConfig.

@Test
public void testConfig() {
    ForestJsonConverter jsonConverter = forestConfiguration.getJsonConverter();
    assertThat(jsonConverter).isNotNull().isInstanceOf(ForestJacksonConverter.class);
    ForestJacksonConverter forestJacksonConverter = (ForestJacksonConverter) jsonConverter;
    assertThat(forestJacksonConverter.getDateFormat()).isEqualTo("yyyy/MM/dd hh:mm:ss");
}
Also used : ForestJsonConverter(com.dtflys.forest.converter.json.ForestJsonConverter) ForestJacksonConverter(com.dtflys.forest.converter.json.ForestJacksonConverter) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 19 with ForestJsonConverter

use of com.dtflys.forest.converter.json.ForestJsonConverter in project forest by dromara.

the class ConfigurationTest method testConfiguration.

public void testConfiguration() {
    applicationContext = new ClassPathXmlApplicationContext(new String[] { "classpath:configuration-test.xml" });
    ForestConfiguration forestConfiguration = (ForestConfiguration) applicationContext.getBean("forestConfiguration2");
    assertNotNull(forestConfiguration);
    assertNotNull(forestConfiguration.getBackend());
    assertEquals(forestConfiguration.getTimeout(), new Integer(30000));
    assertEquals(forestConfiguration.getConnectTimeout(), new Integer(10000));
    assertEquals(forestConfiguration.getMaxConnections(), new Integer(500));
    assertEquals(forestConfiguration.getMaxRouteConnections(), new Integer(500));
    assertEquals(forestConfiguration.getSslProtocol(), "SSLv3");
    assertEquals(forestConfiguration.getVariableValue("baseUrl"), "http://www.thebeastshop.com");
    assertEquals(forestConfiguration.getVariableValue("x"), "0");
    assertEquals(forestConfiguration.getVariableValue("y"), "1");
    assertEquals(forestConfiguration.getBackend().getName(), "httpclient");
    assertEquals("GBK", forestConfiguration.getCharset());
    assertEquals(Boolean.TRUE, Boolean.valueOf(forestConfiguration.isLogEnabled()));
    assertEquals(Boolean.FALSE, Boolean.valueOf(forestConfiguration.isLogResponseStatus()));
    assertEquals(Boolean.TRUE, Boolean.valueOf(forestConfiguration.isLogResponseContent()));
    assertEquals(NoneRetryer.class, forestConfiguration.getRetryer());
    assertTrue(forestConfiguration.getLogHandler() instanceof TestLogHandler);
    ForestJsonConverter jsonConverter = forestConfiguration.getJsonConverter();
    assertNotNull(jsonConverter);
    assertTrue(jsonConverter instanceof ForestGsonConverter);
    assertEquals("yyyy/MM/dd hh:mm:ss", jsonConverter.getDateFormat());
}
Also used : ForestConfiguration(com.dtflys.forest.config.ForestConfiguration) ForestJsonConverter(com.dtflys.forest.converter.json.ForestJsonConverter) TestLogHandler(com.dtflys.spring.test.logging.TestLogHandler) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ForestGsonConverter(com.dtflys.forest.converter.json.ForestGsonConverter)

Example 20 with ForestJsonConverter

use of com.dtflys.forest.converter.json.ForestJsonConverter in project forest by dromara.

the class TestForestConfiguration method testJSONConverterSelect.

@Test
public void testJSONConverterSelect() throws Throwable {
    JSONConverterSelector jsonConverterSelector = new JSONConverterSelector();
    JSONConverterSelector spy = Mockito.spy(jsonConverterSelector);
    Mockito.when(spy.checkFastJSONClass()).thenThrow(new ClassNotFoundException("com.alibaba.fastjson.JSON"));
    ForestJsonConverter jsonConverter = spy.select();
    assertNotNull(jsonConverter);
    assertTrue(jsonConverter instanceof ForestJacksonConverter);
    jsonConverterSelector = new JSONConverterSelector();
    spy = Mockito.spy(jsonConverterSelector);
    Mockito.when(spy.checkFastJSONClass()).thenThrow(new ClassNotFoundException("com.alibaba.fastjson.JSON"));
    Mockito.when(spy.checkJacsonClass()).thenThrow(new ClassNotFoundException("com.fasterxml.jackson.databind.ObjectMapper"));
    jsonConverter = spy.select();
    assertNotNull(jsonConverter);
    assertTrue(jsonConverter instanceof ForestGsonConverter);
    jsonConverterSelector = new JSONConverterSelector();
    spy = Mockito.spy(jsonConverterSelector);
    Mockito.when(spy.checkFastJSONClass()).thenThrow(new ClassNotFoundException("com.alibaba.fastjson.JSON"));
    Mockito.when(spy.checkJacsonClass()).thenThrow(new ClassNotFoundException("com.fasterxml.jackson.databind.ObjectMapper"));
    Mockito.when(spy.checkGsonClass()).thenThrow(new ClassNotFoundException("com.google.gson.JsonParser"));
    jsonConverter = spy.select();
    assertNull(jsonConverter);
}
Also used : ForestJsonConverter(com.dtflys.forest.converter.json.ForestJsonConverter) ForestGsonConverter(com.dtflys.forest.converter.json.ForestGsonConverter) JSONConverterSelector(com.dtflys.forest.converter.json.JSONConverterSelector) ForestJacksonConverter(com.dtflys.forest.converter.json.ForestJacksonConverter) Test(org.junit.Test)

Aggregations

ForestJsonConverter (com.dtflys.forest.converter.json.ForestJsonConverter)20 RequestNameValue (com.dtflys.forest.utils.RequestNameValue)6 Map (java.util.Map)4 Test (org.junit.Test)4 ForestGsonConverter (com.dtflys.forest.converter.json.ForestGsonConverter)3 ForestQueryParameter (com.dtflys.forest.http.ForestQueryParameter)3 ForestRequestBody (com.dtflys.forest.http.ForestRequestBody)3 NameValueRequestBody (com.dtflys.forest.http.body.NameValueRequestBody)3 ObjectRequestBody (com.dtflys.forest.http.body.ObjectRequestBody)3 ForestMultipart (com.dtflys.forest.multipart.ForestMultipart)3 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)3 ForestJacksonConverter (com.dtflys.forest.converter.json.ForestJacksonConverter)2 ForestRuntimeException (com.dtflys.forest.exceptions.ForestRuntimeException)2 ForestVariableUndefinedException (com.dtflys.forest.exceptions.ForestVariableUndefinedException)2 ForestURL (com.dtflys.forest.http.ForestURL)2 LinkedHashMap (java.util.LinkedHashMap)2 LinkedList (java.util.LinkedList)2 ContentType (com.dtflys.forest.backend.ContentType)1 AddressSource (com.dtflys.forest.callback.AddressSource)1 OnError (com.dtflys.forest.callback.OnError)1