Я работаю над spring mock mvc, и я готовил контрольный пример для одного из запросов ниже, это класс контроллера, имеющий запрос типа post
@PostMapping(path=PftConstants.POST_SIGN_ON_URL,produces = {MediaType.APPLICATION_JSON_VALUE} )
@ValidateSession(ignore=true)
public ResponseEntity<SignOnResp> signOn(@ApiParam(name=PftConstants.HEADER_HOME_ID, value = PftConstants.HEADER_HOME_ID_DESC, required = true) @RequestHeader(value = PftConstants.HEADER_HOME_ID, required = false) String lomeId,
@ApiParam(name=PftConstants.HEADER_IP_ADDRESS, value = PftConstants.HEADER_IP_ADDRESS_DESC, required = true) @RequestHeader(value = PftConstants.HEADER_IP_ADDRESS, required = false) String ipAddress,
@ApiParam(name=PftConstants.HEADER_FISERV_AGENT, value = PftConstants.HEADER_FISERV_AGENT_DESC, required = false) @RequestHeader(value = PftConstants.HEADER_FISERV_AGENT, required = false) String fiservUserAgent,
@Valid @ApiParam(name = "signOnRq", value =PftConstants.POST_SIGN_ON_RQ_DESCRIPTION,required = true) @RequestBody SignOnRq signOnRq,BindingResult bindingResult, HttpServletRequest request) {
logger.println(IMessage.INFO,CLASS_NAME + ".signOn()::" + "signOn method start");
SignOnResp signOnResp= new SignOnResp(super.validateBindingResult(bindingResult));
, а ниже класс mock, который у меня естьподготовил для вышеприведенного пост контроллера, но все равно выкидывает исключение 404 не найден пожалуйста посоветуйте как побороть из того же
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes={rtyuuu.class})
public class UserControllerIntegrationTest {
private MockMvc mockMvc;
@Mock
private SignOnService signOnService;
@Mock
public PersonService personService;
@Mock
public CustomerService customerService;
@Mock
private AgreementService agreementService;
@Mock
private DisbursementConfigService disbursementConfigService;
@Mock
private SignOnRqValidator signOnRqValidator;
@Mock
private ValidateTokenRqValidator validateTokenRqValidator;
@Mock
private ValidateTokenService validateTokenService;
@InjectMocks
private UserController userController;
private static final String BASE_URI = "http://fhrfbg78:7001/disbursementServices/v1/users/signOn";
private WebApplicationContext wac;
@Before
public void init(){
MockitoAnnotations.initMocks(this);
mockMvc = MockMvcBuilders
.standaloneSetup(userController)
.build();
}
@Test
public void testPost() throws Exception {
SignOnRq signOnRq = new SignOnRq();
signOnRq.setPassword("abc");
signOnRq.setUserName("abc");
SignOnRq signOnRq1 = new SignOnRq();
signOnRq.setPassword("abc");
signOnRq.setUserName("abc");
signOnRq.setCorrelationId("665356");
signOnRq.setResponseId("79368700");
Gson gson = new Gson();
String jsonString = gson.toJson(signOnRq);
BindingResult result = mock(BindingResult.class);
mockMvc.perform(post(BASE_URI)
.header("homeId", "88851153")
.header("ipAddress", "10.10.19.10")
.header("correlationId", "665656")
.header("X-Fiserv-UserAgent", "DISB.API.1.0")
.contentType(MediaType.APPLICATION_JSON_VALUE)
.content(jsonString))
.andExpect(status().isOk());
}
}