0
こんにちはを使用してある特定のフォームに対処することが可能に
です。私は3つのフォームを持つテンプレートを持っていますが、私はそのうちの1つに対処できません。あなたが見ることができるように、私は複数のフォームを持っていると私は最初にテストしたいは、それがMockMvcを使用してHTMLテンプレートにある特定のフォームに対処することが可能です場合、私はAKSに望んでいた、そこMockMvc
<form action="#" th:object="${illnessform}" method="post" name="illnessform"
th:action="@{/tourmanagement/ill(tour=${tourid}, start=${startDate}, end=${endDate}, tourname=${tour.name})}">
<div id="ill" style="display: none" class="form-group">
<label for="illselect" th:text="#{tourmanagement.whoisill}">Which Tourist Is Ill?</label>
<select class="form-control" id="illselect" name="customer">
<option th:each="customer : ${customerList}" th:value="${customer.account.id}">
<p th:text="${customer.account.id}"></p>
</option>
</select>
<label for="illInf" th:text="#{tourmanagement.moreinfs}">More Information:</label>
<input id="illInf" type="text" class="form-control" required name="moreInf" th:field="*{moreInf}">
<button class="btn btn-info" name="submit" type="submit" th:text="#{contact.submit}">Submit</button>
</div>
</form>
<form action="#" th:object="${insuranceform}" method="post"
th:action="@{/tourmanagement/ins(tour=${tourid}, start=${startDate}, end=${endDate}, tourname=${tour.name})}">
<div id="ins" style="display: none" class="form-group">
<label for="inssellect" th:text="#{tourmanagement.whatkindofins}">What Kind Of Insurance Case?</label>
<select class="form-control" id="inssellect" name="caseType" th:field="*{caseType}">
<option th:text="#{tourmanagement.theft}" th:value="#{tourmanagement.theft}">Theft</option>
<option th:text="#{tourmanagement.accident}" th:value="#{tourmanagement.accident}">Accident</option>
</select>
<label for="inssellecttourist" th:text="#{tourmanagement.whichtourist}">Which Tourist Did It Happen
To?</label>
<select class="form-control" id="inssellecttourist" name="customer" th:field="*{customer}">
<option th:each="customer : ${customerList}" th:value="${customer.account.id}">
<p th:text="${customer.account.id}"></p>
</option>
</select>
<label for="insInf" th:text="#{tourmanagement.moreinfs}">More Information:</label>
<input id="insInf" type="text" class="form-control" required name="moreInf" th:field="*{moreInf}">
<button class="btn btn-info" type="submit" th:text="#{contact.submit}">Submit</button>
</div>
</form>
:
@Test
public void CreateNewIllMessageTest() throws Exception {
initializeDummyTourWithDummyGuide();
User user = userRepository.findUserByName("dummy");
String moreInf = "moreInformation";
mvc.perform(get("/tourmanagement").with(user(user.getUsername()).roles("EMPLOYEE"))).
andExpect(status().isOk()).
andExpect(view().name("tourmanagement")).
andExpect(model().attributeExists("illnessform")).
andExpect(model().attribute("illnessform", hasProperty("customer", is(nullValue())))).
andExpect(model().attribute("illnessform", hasProperty("moreInf", isEmptyOrNullString())));
mvc.perform(post("/tourmanagement").with(user(user.getUsername()).roles("EMPLOYEE")).
param("customer", user.getAccount().getId().toString()).
param("moreInf", moreInf)
).
andExpect(status().is3xxRedirection());
}
このテンプレートは次のとおりです。
は、これは私のテストです。私が手にエラーがある:
java.lang.AssertionError: Range for response status value 405
予想:REDIRECTION 実際:CLIENT_ERROR
at org.springframework.test.util.AssertionErrors.fail(AssertionErrors.java:54)
at org.springframework.test.util.AssertionErrors.assertEquals(AssertionErrors.java:81)
at org.springframework.test.web.servlet.result.StatusResultMatchers$5.match(StatusResultMatchers.java:107)
at org.springframework.test.web.servlet.MockMvc$1.andExpect(MockMvc.java:171)
at kickstart.Message.MessageIntegrationTest.CreateNewIllMessageTest(MessageIntegrationTest.java:145)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:252)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:94)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:191)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
私は任意のヘルプまたはこれらのフォームをテストするための別の方法を本当にいただければ幸いです。
挨拶、アレックス
フォームメソッドが** get **ではなく** post **であるため、 'get(...) 'の代わりに' post(...) 'を使用してください。 –