use of com.dtflys.forest.exceptions.ForestRuntimeException in project forest by dromara.
the class TestSSLClient method testHostVerifier2.
@Test
public void testHostVerifier2() {
sslClient.truestAllGet();
Throwable th = null;
String result = null;
ForestRequest<String> request = sslClient.testHostVerifier2("localhost");
assertThat(request.getHostnameVerifier()).isNotNull().isInstanceOf(MyHostnameVerifier.class);
assertThat(request.getSslSocketFactoryBuilder()).isNotNull().isInstanceOf(com.dtflys.test.http.ssl.MySSLSocketFactoryBuilder.class);
try {
result = request.executeAsString();
} catch (ForestRuntimeException ex) {
th = ex.getCause();
}
assertThat(th).isNotNull().isInstanceOf(SSLPeerUnverifiedException.class);
th = null;
String host = null;
try {
InetAddress addr = InetAddress.getLocalHost();
host = addr.getHostAddress();
} catch (UnknownHostException e) {
e.printStackTrace();
}
request = sslClient.testHostVerifier2(host);
assertThat(request.getHostnameVerifier()).isNotNull().isInstanceOf(MyHostnameVerifier.class);
assertThat(request.getSslSocketFactoryBuilder()).isNotNull().isInstanceOf(com.dtflys.test.http.ssl.MySSLSocketFactoryBuilder.class);
try {
result = request.executeAsString();
} catch (ForestRuntimeException ex) {
th = ex.getCause();
}
assertThat(th).isNull();
assertThat(result).isNotNull().isEqualTo(EXPECTED);
}
use of com.dtflys.forest.exceptions.ForestRuntimeException in project forest by dromara.
the class TestForestJacksonConverter method testConvertToJsonError.
@Test
public void testConvertToJsonError() {
ForestJacksonConverter forestJacksonConverter = new ForestJacksonConverter();
Map map = new HashMap();
map.put("ref", map);
boolean error = false;
try {
forestJacksonConverter.encodeToString(map);
} catch (ForestRuntimeException e) {
error = true;
assertNotNull(e.getCause());
}
assertTrue(error);
}
use of com.dtflys.forest.exceptions.ForestRuntimeException in project forest by dromara.
the class TestGsonConverter method testConvertToJavaError.
@Test
public void testConvertToJavaError() {
String jsonText = "{\"a\":1, ";
boolean error = false;
ForestGsonConverter gsonConverter = new ForestGsonConverter();
try {
gsonConverter.convertToJavaObject(jsonText, Map.class);
} catch (ForestRuntimeException e) {
error = true;
assertNotNull(e.getCause());
}
assertTrue(error);
error = false;
try {
gsonConverter.convertToJavaObject(jsonText, new TypeToken<Map>() {
}.getType());
} catch (ForestRuntimeException e) {
error = true;
assertNotNull(e.getCause());
}
assertTrue(error);
jsonText = "[1, 2,";
try {
gsonConverter.convertToJavaObject(jsonText, Map.class);
} catch (ForestRuntimeException e) {
error = true;
assertNotNull(e.getCause());
}
assertTrue(error);
}
use of com.dtflys.forest.exceptions.ForestRuntimeException in project forest by dromara.
the class TestJaxbConverter method testConvertToXmlError.
@Test
public void testConvertToXmlError() {
BadUser user = new BadUser();
user.setName("Peter");
user.setAge(32);
ForestJaxbConverter forestJaxbConverter = new ForestJaxbConverter();
boolean error = false;
try {
forestJaxbConverter.encodeToString(user);
} catch (ForestRuntimeException e) {
error = true;
}
assertTrue(error);
}
use of com.dtflys.forest.exceptions.ForestRuntimeException in project forest by dromara.
the class TestJaxbConverter method convertToJavaObjectError.
@Test
public void convertToJavaObjectError() {
ForestJaxbConverter forestJaxbConverter = new ForestJaxbConverter();
String xmlText = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<user>\n" + "<name>Peter</name>\n" + "<age>32</age>\n" + "</user";
boolean error = false;
try {
forestJaxbConverter.convertToJavaObject(xmlText, User.class);
} catch (ForestRuntimeException e) {
error = true;
assertNotNull(e.getCause());
}
assertTrue(error);
}
Aggregations