Search in sources :

Example 11 with RequestTemplate

use of feign.RequestTemplate in project feign by OpenFeign.

the class JAXBCodecTest method encodesXmlWithCustomJAXBEncoding.

@Test
public void encodesXmlWithCustomJAXBEncoding() throws Exception {
    JAXBContextFactory jaxbContextFactory = new JAXBContextFactory.Builder().withMarshallerJAXBEncoding("UTF-16").build();
    Encoder encoder = new JAXBEncoder(jaxbContextFactory);
    MockObject mock = new MockObject();
    mock.value = "Test";
    RequestTemplate template = new RequestTemplate();
    encoder.encode(mock, MockObject.class, template);
    assertThat(template).hasBody("<?xml version=\"1.0\" encoding=\"UTF-16\" " + "standalone=\"yes\"?><mockObject><value>Test</value></mockObject>");
}
Also used : Encoder(feign.codec.Encoder) RequestTemplate(feign.RequestTemplate) Test(org.junit.Test)

Example 12 with RequestTemplate

use of feign.RequestTemplate in project feign by OpenFeign.

the class DefaultEncoderTest method testEncodesStrings.

@Test
public void testEncodesStrings() throws Exception {
    String content = "This is my content";
    RequestTemplate template = new RequestTemplate();
    encoder.encode(content, String.class, template);
    assertEquals(content, new String(template.body(), UTF_8));
}
Also used : RequestTemplate(feign.RequestTemplate) Test(org.junit.Test)

Example 13 with RequestTemplate

use of feign.RequestTemplate in project feign by OpenFeign.

the class DefaultEncoderTest method testEncodesByteArray.

@Test
public void testEncodesByteArray() throws Exception {
    byte[] content = { 12, 34, 56 };
    RequestTemplate template = new RequestTemplate();
    encoder.encode(content, byte[].class, template);
    assertTrue(Arrays.equals(content, template.body()));
}
Also used : RequestTemplate(feign.RequestTemplate) Test(org.junit.Test)

Example 14 with RequestTemplate

use of feign.RequestTemplate in project feign by OpenFeign.

the class JAXBCodecTest method encodesXmlWithCustomJAXBSchemaLocation.

@Test
public void encodesXmlWithCustomJAXBSchemaLocation() throws Exception {
    JAXBContextFactory jaxbContextFactory = new JAXBContextFactory.Builder().withMarshallerSchemaLocation("http://apihost http://apihost/schema.xsd").build();
    Encoder encoder = new JAXBEncoder(jaxbContextFactory);
    MockObject mock = new MockObject();
    mock.value = "Test";
    RequestTemplate template = new RequestTemplate();
    encoder.encode(mock, MockObject.class, template);
    assertThat(template).hasBody("<?xml version=\"1.0\" encoding=\"UTF-8\" " + "standalone=\"yes\"?><mockObject xsi:schemaLocation=\"http://apihost " + "http://apihost/schema.xsd\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">" + "<value>Test</value></mockObject>");
}
Also used : Encoder(feign.codec.Encoder) RequestTemplate(feign.RequestTemplate) Test(org.junit.Test)

Example 15 with RequestTemplate

use of feign.RequestTemplate in project feign by OpenFeign.

the class JAXBCodecTest method encodesXml.

@Test
public void encodesXml() throws Exception {
    MockObject mock = new MockObject();
    mock.value = "Test";
    RequestTemplate template = new RequestTemplate();
    new JAXBEncoder(new JAXBContextFactory.Builder().build()).encode(mock, MockObject.class, template);
    assertThat(template).hasBody("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><mockObject><value>Test</value></mockObject>");
}
Also used : RequestTemplate(feign.RequestTemplate) Test(org.junit.Test)

Aggregations

RequestTemplate (feign.RequestTemplate)18 Test (org.junit.Test)18 Encoder (feign.codec.Encoder)4 LinkedHashMap (java.util.LinkedHashMap)4 TypeReference (com.fasterxml.jackson.core.type.TypeReference)2 TypeToken (com.google.gson.reflect.TypeToken)2 LinkedList (java.util.LinkedList)2 SimpleModule (com.fasterxml.jackson.databind.module.SimpleModule)1 Type (java.lang.reflect.Type)1 Date (java.util.Date)1 Map (java.util.Map)1 XmlAccessType (javax.xml.bind.annotation.XmlAccessType)1 XmlAccessorType (javax.xml.bind.annotation.XmlAccessorType)1