use of com.dtflys.forest.config.ForestConfiguration in project forest by dromara.
the class ConverterBeanListener method onApplicationEvent.
@Override
public void onApplicationEvent(ApplicationContextEvent event) {
ApplicationContext applicationContext = event.getApplicationContext();
ForestConfiguration forestConfiguration = this.forestConfiguration;
if (forestConfiguration == null) {
try {
forestConfiguration = applicationContext.getBean(ForestConfiguration.class);
} catch (Exception ignored) {
throw new ForestRuntimeException("property forestConfiguration undefined", ignored);
}
}
Map<String, ForestConverter> forestConverterMap = applicationContext.getBeansOfType(ForestConverter.class);
for (ForestConverter forestConverter : forestConverterMap.values()) {
forestConfiguration.getConverterMap().put(forestConverter.getDataType(), forestConverter);
}
}
use of com.dtflys.forest.config.ForestConfiguration 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());
}
use of com.dtflys.forest.config.ForestConfiguration in project forest by dromara.
the class TestForestConfiguration method testDefault.
@Test
public void testDefault() {
ForestConfiguration configuration = ForestConfiguration.createConfiguration();
assertEquals("forestConfiguration" + configuration.hashCode(), configuration.getId());
assertEquals(Integer.valueOf(3000), configuration.getTimeout());
assertEquals(null, configuration.getConnectTimeout());
assertEquals(null, configuration.getReadTimeout());
assertEquals(Integer.valueOf(500), configuration.getMaxConnections());
assertEquals(Integer.valueOf(500), configuration.getMaxRouteConnections());
assertNotNull(configuration.getJsonConverter());
}
use of com.dtflys.forest.config.ForestConfiguration in project forest by dromara.
the class TestForestConfiguration method testDefaultParameters.
@Test
public void testDefaultParameters() {
ForestConfiguration configuration = ForestConfiguration.createConfiguration();
List<RequestNameValue> defaultParameters = new LinkedList<>();
defaultParameters.add(new RequestNameValue("name", "Peter", TARGET_BODY));
defaultParameters.add(new RequestNameValue("age", "15", TARGET_BODY));
configuration.setDefaultParameters(defaultParameters);
assertEquals(defaultParameters, configuration.getDefaultParameters());
}
use of com.dtflys.forest.config.ForestConfiguration in project forest by dromara.
the class TestForestConfiguration method testVars.
@Test
public void testVars() {
ForestConfiguration configuration = ForestConfiguration.createConfiguration();
configuration.setVariableValue("name", "Peter");
configuration.setVariableValue("baseUrl", "http://abc.com");
assertEquals("Peter", configuration.getVariableValue("name"));
assertEquals("http://abc.com", configuration.getVariableValue("baseUrl"));
Map<String, Object> varMap = new HashMap<>();
varMap.put("name", "Linda");
varMap.put("abc", 123);
configuration.setVariables(varMap);
assertThat(configuration.getVariableValue("name")).isEqualTo("Linda");
assertThat(configuration.getVariableValue("abc")).isEqualTo(123);
AtomicInteger value = new AtomicInteger(0);
configuration.setVariableValue("foo", (method) -> value.getAndIncrement());
assertThat(configuration.getVariableValue("foo")).isEqualTo(0);
assertThat(configuration.getVariableValue("foo")).isEqualTo(1);
}
Aggregations