я работаю сСпок не работает ожидаемым "совпавших вызовов", работающих через @WebAppConfiguration
- STS
- Gradle
- Спок Ядро
- Спок Отчеты
- Спок Spring
- Испытание пружины MVC
У меня есть следующий код теста:
@WebAppConfiguration
@ContextConfiguration(classes=[RootApplicationContextConfig.class,ServletApplicationContextConfig.class])
@SuppressWarnings("deprecation")
class PersonaXmlFindOneControllerTest extends Specification {
@Autowired
private WebApplicationContext webApplicationContext;
private MockMvc mockMvc;
private PersonaXmlFindOneController personaXmlFindOneController
def setup(){
mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build();
personaXmlFindOneController = webApplicationContext.getBean(PersonaXmlFindOneController.class);
println personaXmlFindOneController.toString()
}
def "findOneRequestParamById deberia ser llamado"(){
String url = null
ResultActions resultActions = null
given: "The URL being used "
url = "some url to test"
when: "When the URL is being calling with a GET"
resultActions = mockMvc.perform(get(url, PersonaControllerSupport.ID)).andDo(print())
then: "...."
resultActions.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_XML))
.andExpect(xpath("persona").exists())
.andExpect(xpath("persona").nodeCount(1))
….
//then:
//1 * personaXmlFindOneController.findOneRequestParamById(_ as String)
}
код работает нормально. Он проходит.
Furthemore: через Gradle Отчет об испытаниях благодаря andDo (печать()) Я могу подтвердить, что personaXmlFindOneController.findOneRequestParamById был вызван.
Это означает
Handler:
Type = com.manuel.jordan.controller.xml.PersonaXmlFindOneController
Method = public com.manuel.jordan.domain.xml.PersonaXml com.manuel.jordan.controller.xml.PersonaXmlFindOneController.findOneRequestParamById(java.lang.String)
Теперь Если включить
//then:
//1 * personaXmlFindOneController.findOneRequestParamById(_ as String)
код не удается,
Too few invocations for:
1 * personaXmlFindOneController.findOneRequestParamById(_ as String) (0 invocations)
Unmatched invocations (ordered by similarity):
None
Заметим, что в способе установки, она была восстановлена через
personaXmlFindOneController = webApplicationContext.getBean(PersonaXmlFindOneController.class);
Таким образом, что отсутствует или что не так?
Имеет смысл вашего ответа, позвольте мне подтвердить это через проблему Spring JIRA. благодаря –