use of com.dtflys.forest.config.ForestConfiguration in project forest by dromara.
the class ForestBeanProcessor method processBean.
private void processBean(Object bean, Class beanClass) {
Method[] methods = beanClass.getDeclaredMethods();
for (Method method : methods) {
BindingVar annotation = method.getAnnotation(BindingVar.class);
if (annotation == null) {
continue;
}
String confId = annotation.configuration();
ForestConfiguration configuration = null;
if (StringUtils.isNotBlank(confId)) {
configuration = Forest.config(confId);
} else {
configuration = Forest.config();
}
String varName = annotation.value();
SpringVariableValue variableValue = new SpringVariableValue(bean, method);
configuration.setVariableValue(varName, variableValue);
}
}
use of com.dtflys.forest.config.ForestConfiguration in project forest by dromara.
the class SSLTest method testSSL.
public void testSSL() {
applicationContext = new ClassPathXmlApplicationContext(new String[] { "classpath:ssl-test.xml" });
ForestConfiguration configuration = (ForestConfiguration) applicationContext.getBean("forestConfiguration");
SSLKeyStore keyStore = configuration.getKeyStore("keystore1");
assertNotNull(keyStore);
assertNotNull(keyStore.getInputStream());
assertEquals("keystore1", keyStore.getId());
assertEquals("123456", keyStore.getKeystorePass());
assertEquals("jks", keyStore.getKeystoreType());
assertThat(keyStore.getSslSocketFactoryBuilder()).isNotNull().isInstanceOf(MySSLSocketFactoryBuilder.class);
assertThat(keyStore.getHostnameVerifier()).isNotNull().isInstanceOf(MyHostnameVerifier.class);
BeastshopClient beastshopClient = (BeastshopClient) applicationContext.getBean("beastshopClient");
assertNotNull(beastshopClient);
String result = beastshopClient.index();
assertNotNull(result);
Throwable th = null;
try {
beastshopClient.index2();
} catch (ForestRuntimeException ex) {
th = ex.getCause();
}
assertThat(th).isNotNull();
}
use of com.dtflys.forest.config.ForestConfiguration in project forest by dromara.
the class TestForestConfiguration method testBackend.
@Test
public void testBackend() {
ForestConfiguration configuration = ForestConfiguration.createConfiguration();
configuration.setBackendName("okhttp3");
assertEquals("okhttp3", configuration.getBackend().getName());
configuration.setBackend(null);
configuration.setBackendName("httpclient");
assertEquals("httpclient", configuration.getBackend().getName());
HttpBackendSelector originSelector = new HttpBackendSelector();
HttpBackendSelector selector = Mockito.spy(originSelector);
configuration.setHttpBackendSelector(selector);
Mockito.when(selector.findOkHttp3BackendInstance()).thenReturn(null);
configuration.setBackendName(null);
configuration.setBackend(null);
Assert.assertEquals("httpclient", configuration.getBackend().getName());
Mockito.when(selector.findHttpclientBackendInstance()).thenReturn(null);
configuration.setBackendName(null);
configuration.setBackend(null);
boolean thrown = false;
try {
HttpBackend backend = configuration.getBackend();
System.out.print(backend);
} catch (ForestRuntimeException e) {
thrown = true;
}
assertTrue(thrown);
}
use of com.dtflys.forest.config.ForestConfiguration in project forest by dromara.
the class TestForestConfiguration method testDefaultHeaders.
@Test
public void testDefaultHeaders() {
ForestConfiguration configuration = ForestConfiguration.createConfiguration();
List<RequestNameValue> defaultHeaders = new LinkedList<>();
defaultHeaders.add(new RequestNameValue("Accept", "text/html", TARGET_HEADER));
configuration.setDefaultHeaders(defaultHeaders);
assertEquals(defaultHeaders, configuration.getDefaultHeaders());
}
use of com.dtflys.forest.config.ForestConfiguration in project forest by dromara.
the class TestAutoConverter method getConverter.
private DefaultAutoConverter getConverter() {
ForestConfiguration configuration = ForestConfiguration.createConfiguration();
DefaultAutoConverter autoConverter = (DefaultAutoConverter) configuration.getConverterMap().get(ForestDataType.AUTO);
assertNotNull(autoConverter);
return autoConverter;
}
Aggregations