test serializations REST JAXRS

[亡魂溺海] 提交于 2019-12-25 14:09:15

问题


I'm built REST services using JAXRS. I'd like to test how JAXRS implementation serializes the body content of each request, and be able to provide some test examples in order to check the body content is serialized correctly.

For example:

public void createOrUpdate(FollowUpActivityDTO dto) throws RepositorySystemException
{

}

I'm using jackson provider in order to do that:

compile group: 'com.fasterxml.jackson.jaxrs',
        name: 'jackson-jaxrs-json-provider',
        version: '2.5.3'

I'd like to provide some json examples, and see what's the serialzed result, so which the content of dto parameter.

Any ideas? I've took a look on Rest-Assured, but I don't whether it's exactly for checking my affair.

Example

public class FollowUpActivityDTOSerializationTest
{

  private ObjectMapper mapper;

  @Before
  public void initialize()
  {
    this.mapper = new ObjectMapper();
  }

  @Test
  public void emptyJSON()
  { 
    String emptyJSON = "{\"id\": \"id\"}";

    try {
      FollowUpActivityDTO dto = this.mapper.readValue(emptyJSON, FollowUpActivityDTO.class);
      assertNotNull(dto);
      assertEquals(dto.getId(), "id");
    } catch (IOException e) {
      fail(e.getMessage());
    }
  }

}

It works now, However, how I know what's the configuration of the internal jackson-provider. By now, my configuration is a single sentence like: this.mapper = new ObjectMapper();. However, I don't know how jackson-provider initializes its internal ObjectMapper?

来源:https://stackoverflow.com/questions/33120094/test-serializations-rest-jaxrs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!