?????????????ж????????????????в????????????????????controller?е????????????
?????????????????????
???????????????????????????????÷??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????е?????????????????????У????????????????????????????????????в???????????????????????????????????????????????????????????????У??????????????????????????????????????????????????????????????????????Э????
??????Java?????У?Spring?????Java EE?????????????????????????????????????????API?????????JDBC????????????????????Spring??Java EE???п???????ó???????????????У???????????н??в???????????????????????????????????????????????С?
???????????????????У????????????????в?????????????в????
????Spring????????????autowiring?????????????????
??????model?ж?PetType????????populatePetTypes()????
????URL???????????controller????????????????@RequestMapping
??????HTTP???ж?Pet????????????@SessionAttributes("pet")???
?????????????
????????????????????“?????????”??????????????????Щ??????????????????????Spring????????????????????????????????????Java EE????????????????Arquillian???????????????????????С???????Java EE????ó????д??????????????????????CDI????Arquillian????????????Щ????????????????Щ??????????????????????????????Pet Clinic?????????????????????Щ????????????????
????Spring?е?JUnit????
????????JUnit???????????????????????????????????????Spring?????????????JUnit???????????????????????????Spring??????????????????????@RunWith?????????????
????@RunWith(SpringJUnit4ClassRunner.class)
????public class PetControllerIT { ... }Spring????????????????????????????????????XML?????????????????е?Java“????”??????????????????????????????????????????????????????????????????????????????????????????Щ?????????????????????@ContextConfiguration??????????á?
????@ContextConfiguration("classpath:spring/business-config.xml")
????public class PetControllerIT { ... }??Spring????????????????????ó???Χ??????????????????Щ?????????м????????????????????????????????????????????????@ActiveProfile??????ɡ?
????@ActiveProfiles("jdbc")
????public class PetControllerIT { ... }????JUnit????????Spring bean???????????????????????????Spring MVC controller?????????????и?????????
????Spring?е????web??????
????????web??ó????????Spring??????????????????????????????????е??-???????????е???????web????????controller????????????????????????????а????????????????????????????????repository???????????????????????????????????@ContextHierarchy??????????????????????????????????@ContextConfiguration?????
?????????????????????У?business-config.xml???????????mvc-core-config.xml??????????
????@ContextHierarchy({
????@ContextConfiguration("classpath:spring/business-config.xml")??
????@ContextConfiguration("classpath:spring/mvc-core-config.xml")
????})?????????????@WebAppConfiguration?????????????WebApplicationContext?????????????????????ApplicationContext??
????????controller
??????????а???????????????????ú?web???????????????????????controller???MockMvc???????????е???????????а??????????????
???????Request????????????????Fake??????
???????Request???????????controller???????е???
???????Result???????????????????????????
????MockMvc??????????????MockMvcBuilders?????????????????????????????????????????????controller?????????????????????????????????ó?????????????????????£?????????WebApplicationContext?????????????????????????????????????????ж?????????????????autowire???ɡ?
????@RunWith(SpringJUnit4ClassRunner.class)
????public class PetControllerIT {
????@Autowired
????private WebApplicationContext context;
????}???????????perform(RequestBuilder)??????о????????MockMvc???????????RequestBuilder????????????????MockMvcRequestBuilders?е???????????????????????????????????????????HTTP???????????
?????????£???????????????′???????????/owners/1/pets/new·????GET???á?
????MockMvc mockMvc = MockMvcBuilders.standaloneSetup(PetController.class).build();
????RequestBuilder getNewPet = MockMvcRequestBuilders.get("/owners/1/pets/new");
????mockMvc.perform(getNewPet);??Spring?????ResultMatcher???????????????????????????MockMvc??fluent API??????cookie???????塢???????HTTP??????????Щ???????????м??????????????