title: How to pass @RequestBody parameter of controller using MockMVC
body: <p>Parameters with @RequestParam annotation can be passed by using : post("/******/***").param("variable", "value")</p>
  
  <p>but how can I pass value of parameter having @RequestBody annotation?</p>
  
  <p>My test method is :</p>
  
  <pre><code>@Test
      public void testCreateCloudCredential() throws Exception {
  
          CloudCredentialsBean cloudCredentialsBean = new CloudCredentialsBean();
          cloudCredentialsBean.setCloudType("cloudstack");
          cloudCredentialsBean.setEndPoint("cloudstackendPoint");
          cloudCredentialsBean.setUserName("cloudstackuserName");
          cloudCredentialsBean.setPassword("cloudstackpassword");
          cloudCredentialsBean.setProviderCredential("cloudstackproviderCredential");
          cloudCredentialsBean.setProviderIdentity("cloudstackproviderIdentity");
          cloudCredentialsBean.setProviderName("cloudstackproviderName");
          cloudCredentialsBean.setTenantId(78);
          cloudCredentialsBean.setCredentialId(98);
  
          StatusBean statusBean = new StatusBean();
          statusBean.setCode(200);
          statusBean.setStatus(Constants.SUCCESS);
          statusBean.setMessage("Credential Created Successfully");
  
          Gson gson = new Gson();
          String json = gson.toJson(cloudCredentialsBean);
          ArgumentCaptor&lt;String&gt; getArgumentCaptor =
              ArgumentCaptor.forClass(String.class);
          ArgumentCaptor&lt;Integer&gt; getInteger = ArgumentCaptor.forClass(Integer.class);
  
          ArgumentCaptor&lt;CloudCredentialsBean&gt; getArgumentCaptorCredential =
              ArgumentCaptor.forClass(CloudCredentialsBean.class);
          when(
              userManagementHelper.createCloudCredential(getInteger.capture(),
                      getArgumentCaptorCredential.capture())).thenReturn(
              new ResponseEntity&lt;StatusBean&gt;(statusBean, new HttpHeaders(),
                  HttpStatus.OK));
  
          mockMvc.perform(
              post("/usermgmt/createCloudCredential").param("username", "aricloud_admin").contentType(
                  MediaType.APPLICATION_JSON).content(json)).andExpect(
              status().isOk());
  
      }
  </code></pre>
  
  <p>Controller method that is being tested is :</p>
  
  <pre><code>@RequestMapping(value = "/createCloudCredential", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
      @ResponseBody
      public ResponseEntity&lt;StatusBean&gt; createCloudCredential(
              @RequestParam("userId") int userId,
           @RequestBody CloudCredentialsBean credential) {            
              return userManagementHepler.createCloudCredential(userId, credential);
          }   
  </code></pre>
  
  <p>Error that I am getting is :
  <a href="https://i.stack.imgur.com/7nAeB.png" rel="noreferrer"><img src="https://i.stack.imgur.com/7nAeB.png" alt="enter image description here"></a>
  How can I pass a mock value for <strong>credential</strong> here?</p>