use of com.dtflys.forest.converter.json.ForestGsonConverter in project forest by dromara.
the class TestGsonConverter method testJavaObjectToMap.
@Test
public void testJavaObjectToMap() {
Coordinate coordinate = new Coordinate("11.11111", "22.22222");
ForestGsonConverter gsonConverter = new ForestGsonConverter();
Map map = gsonConverter.convertObjectToMap(coordinate);
assertNotNull(map);
assertEquals("11.11111", map.get("longitude"));
assertEquals("22.22222", map.get("latitude"));
}
use of com.dtflys.forest.converter.json.ForestGsonConverter in project forest by dromara.
the class TestGsonConverter method testDate.
@Test
public void testDate() throws ParseException {
ForestGsonConverter gsonConverter = new ForestGsonConverter();
String json = "{\"name\":\"foo\",\"date\":\"2020-10-10 10:12:00\"}";
gsonConverter.setDateFormat("yyyy-MM-dd hh:mm:ss");
TestJsonObj testJsonObj = gsonConverter.convertToJavaObject(json, TestJsonObj.class);
assertNotNull(testJsonObj);
assertEquals("foo", testJsonObj.getName());
assertDateEquals("2020-10-10 10:12:00", testJsonObj.getDate(), "yyyy-MM-dd hh:mm:ss");
json = "{\"name\":\"foo\",\"date\":\"2020/10/10 10:12:00\"}";
gsonConverter.setDateFormat("yyyy/MM/dd hh:mm:ss");
testJsonObj = gsonConverter.convertToJavaObject(json, TestJsonObj.class);
assertNotNull(testJsonObj);
assertEquals("foo", testJsonObj.getName());
assertDateEquals("2020-10-10 10:12:00", testJsonObj.getDate(), "yyyy-MM-dd hh:mm:ss");
}
use of com.dtflys.forest.converter.json.ForestGsonConverter in project forest by dromara.
the class TestGsonConverter method testConvertToJson.
@Test
public void testConvertToJson() {
ForestGsonConverter gsonConverter = new ForestGsonConverter();
String text = gsonConverter.encodeToString(new Integer[] { 100, 10 });
Assert.assertEquals("[100,10]", text);
}
use of com.dtflys.forest.converter.json.ForestGsonConverter 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");
}
use of com.dtflys.forest.converter.json.ForestGsonConverter 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());
}
Aggregations