MockMvc 模型为空

MockMvc the Model is Null

我正在使用 JUnit 和 MocMvc 测试控制器,如下所示: 测试失败,因为模型为空,但是当我调试时,我确定模型属性包含正确的值 控制器:

@RequestMapping("/login/role")
public String roleSelection(Model model, HttpServletRequest request, HttpSession session) {
String name= request.getParameter("Name");        
model.addAttribute("organization", name);
// some code to generate url 
return  "redirect:"+url;  
} 

JUnit :

@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = WebEnvironment.MOCK)
@ContextConfiguration  
@WebAppConfiguration
public class YXControllerTest {

 @Autowired
 private WebApplicationContext context;

 @Autowired
 private MockHttpServletRequest request;

 @Autowired
 private MockHttpSession session;

private MockMvc mvc;
@Before
public void setUp() throws Exception {
     MockitoAnnotations.initMocks(this);
     mvc = MockMvcBuilders.webAppContextSetup(context)
              .apply(springSecurity())
              .build()  }
 @Test
@WithMockUser(value="admin@bbc.com",password = "pasword")

public void givenAuthRequestOnPrivateService() throws Exception {

     List<String> authorityList = new ArrayList<String>();
     authorityList.add("USER");
     Map<String, List<String>> roleMap = new HashMap();
     roleMap.put("ROL", authorityList);

     this. mvc.perform(get("/login/role").param("Name", "ROL") ).andDo(print())
    .andExpect(status().is3xxRedirection())
    .andExpect(view().name("redirect:/itera/clients"))
    .andExpect( model().attribute("organization", hasSize(1)));
   ...
   }

Print() 显示;

  ModelAndView:
    View name = redirect:/itera/clients
         View = null
        Model = null

欢迎任何帮助

@Deinum 评论在我的学习过程中指导我。

https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/web/servlet/mvc/support/RedirectAttributes.html