title: How to do java unit test with protobuf for controller?
body: <p>I have a spring boot rest controller with requestBody &amp; responseBody both protobuf. like below :</p>
  <pre><code>@RequestMapping(value = &quot;/position/open&quot;, produces = &quot;application/x-protobuf&quot;)
  @ResponseBody
  public MsgProto.Response positionOpen(@RequestBody MsgProto.Request request)throws Exception {
      log.info(&quot;start /position/open&quot;);
      return orderPositionService.addOrder(request);
  }
  </code></pre>
  <p>Now I want to do a unit test using <strong>mockMvc</strong> to test the controller, but it failed every time. I believe it is the code below which is wrong to fire an HTTP request with <strong>protobuf</strong>, any idea how to resolve it?</p>
  <pre><code>mockMvc.perform(post(&quot;/position/open&quot;).contentType(&quot;application/x-protobuf&quot;)
              .content(ObjectsMock.mockMsgProtoRequest().toByteArray())).andDo(print())
              .andExpect(status().isOk());
  </code></pre>
  <p>Exception :</p>
  <pre><code>Resolved Exception:
           Type = org.springframework.web.HttpMediaTypeNotSupportedException
  MockHttpServletResponse:
         Status = 415
  Error message = null
        Headers = [Accept:&quot;application/json, application/octet-stream, 
  application/xml, application/*+json, text/plain, text/xml, application/x-www- 
  form-urlencoded, application/*+xml, multipart/form-data, multipart/mixed, */*&quot;]
  </code></pre>