1
I’m trying to test the method below my controller:
@RequestMapping(value = "/listar", method = RequestMethod.GET)
public ModelAndView iniciaTela(ModelAndView model, HttpServletRequest request){
final ParametroEnvioManualVO parametroEnvioManualVO = new ParametroEnvioManualVO();
final PerfilUsuarioLogadoVO perfilUsuarioLogado = (PerfilUsuarioLogadoVO) request
.getSession().getAttribute(AbstractConstantes.PERFIL_USUARIO_LOGADO);
String strCodigoUnidadeUsuario = perfilUsuarioLogado.getNuUnidade();
parametroEnvioManualVO.setCodigoUnidadeUsuario(strCodigoUnidadeUsuario);
parametroEnvioManualVO.setNomeUnidadeUsuario(perfilUsuarioLogado.getSgUnidade());
List<ModeloMensagemUnidadeVO> listaModelos = bean.obterModelosAutorizadosUnidade(Integer.parseInt(strCodigoUnidadeUsuario));
parametroEnvioManualVO.setListaModelos(listaModelos);
model.addObject(SESSION_ATTRIBUTES, parametroEnvioManualVO);
model.setViewName(VIEW_NAME);
return model;
}
However, I am not able to simulate an Httpsession to pass the profileUsuarioLogized object, as it is from it that the controller searches for a parameter to query models and return to the model. I’m trying with Mockito, but I’m banging my head here.... My challenge is to mount Httpservletrequest with an Httpsession inside and inside the profileUsuarioLog as parameter.
Thanks in advance!
Thanks man. But I’m getting this error below when trying to instantiate Mockhttpservletrequest():
– André Luiz de Paula Britto
If you can supplement the question with your
pom.xml
, seems to be a problem related to a libs conflict, night put mypom.xml
for you to take a look– nullptr
It was the same mistake I was facing here before opening the topic. The following link is the pom: https://github.com/andreluizpb/geral/blob/master/pom.xml
– André Luiz de Paula Britto
The error is this:
java
java.lang.NoSuchMethodError: org.springframework.util.StreamUtils.emptyInput()Ljava/io/InputStream;
 at org.springframework.mock.web.MockHttpServletRequest.<clinit>(MockHttpServletRequest.java:102)
 at xxx.controller.ManterEnvioManualControllerTest.getMockServletRequest(ManterEnvioManualControllerTest.java:110)

– André Luiz de Paula Britto
I think there is room for a new question to resolve this conflict of versions, since the original question has already been answered
– nullptr