I try to junit the following controller
  @RequestMapping(value="actions.htm", params="reqType=delete",method=RequestMethod.POST)
  @ResponseBody
  public String deletePendingAction(@RequestParam("aPk") Long aPk)
  {
    pendingActionsService.deletePendingAction(aPk);
    return "Deleted";
  }
I use params="reqType=delete" and this is I think the reason why junit fails to map to the controller. I tested all other controllers and they work fine without params tag to the controller. My junit config is:
@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
@ContextConfiguration(classes = ApplicationConfig.class,loader = AnnotationConfigWebContextLoader.class)
@TransactionConfiguration(defaultRollback = true)
@Transactional
public class JUnitTests {
  @Autowired
  private WebApplicationContext wac;
  private MockMvc mockMvc;
   @Before
   public void SetupContext()
   {
     this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build();
   }
   @Test
   public void testController() throws Exception
   {
      this.mockMvc.perform(post("/actions.htm","reqType=delete").param("aPk","2"));
   }
}
How do I translate this params tag to the spring mvc junit? Thank you
add param `reqType=delete' to url.
this.mockMvc.perform(post("/actions.htm?reqType=delete")
                .param("aPk", "2")).andReturn().getResponse().getStatus());
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With