Search in sources :

Example 46 with ForestRuntimeException

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);
}
Also used : UnknownHostException(java.net.UnknownHostException) ForestRuntimeException(com.dtflys.forest.exceptions.ForestRuntimeException) InetAddress(java.net.InetAddress)

Example 47 with ForestRuntimeException

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);
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ForestRuntimeException(com.dtflys.forest.exceptions.ForestRuntimeException) ForestJacksonConverter(com.dtflys.forest.converter.json.ForestJacksonConverter) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Test(org.junit.Test)

Example 48 with ForestRuntimeException

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);
}
Also used : TypeToken(com.google.gson.reflect.TypeToken) ForestGsonConverter(com.dtflys.forest.converter.json.ForestGsonConverter) ForestRuntimeException(com.dtflys.forest.exceptions.ForestRuntimeException) Test(org.junit.Test)

Example 49 with ForestRuntimeException

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);
}
Also used : ForestJaxbConverter(com.dtflys.forest.converter.xml.ForestJaxbConverter) ForestRuntimeException(com.dtflys.forest.exceptions.ForestRuntimeException) Test(org.junit.Test)

Example 50 with ForestRuntimeException

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);
}
Also used : ForestJaxbConverter(com.dtflys.forest.converter.xml.ForestJaxbConverter) ForestRuntimeException(com.dtflys.forest.exceptions.ForestRuntimeException) Test(org.junit.Test)

Aggregations

ForestRuntimeException (com.dtflys.forest.exceptions.ForestRuntimeException)64 Test (org.junit.Test)14 Map (java.util.Map)9 ForestConfiguration (com.dtflys.forest.config.ForestConfiguration)7 MetaRequest (com.dtflys.forest.reflection.MetaRequest)6 ForestLogHandler (com.dtflys.forest.logging.ForestLogHandler)5 MappingParameter (com.dtflys.forest.mapping.MappingParameter)5 Method (java.lang.reflect.Method)5 Parameter (java.lang.reflect.Parameter)5 HashMap (java.util.HashMap)5 LinkedHashMap (java.util.LinkedHashMap)5 SSLKeyStore (com.dtflys.forest.ssl.SSLKeyStore)4 IOException (java.io.IOException)4 Annotation (java.lang.annotation.Annotation)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 MalformedURLException (java.net.MalformedURLException)4 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)4 ForestConverter (com.dtflys.forest.converter.ForestConverter)3 ForestRequest (com.dtflys.forest.http.ForestRequest)3 Interceptor (com.dtflys.forest.interceptor.Interceptor)3