1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
|
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:spring-servlet.xml"})
public final class AvalibilityControllerTest {
@Autowired
private RequestMappingHandlerAdapter handlerAdapter;
@Autowired
private RequestMappingHandlerMapping handlerMapping;
private MockHttpServletRequest request;
private MockHttpServletResponse response;
private static final Logger logger = LoggerFactory.getLogger(AvalibilityControllerTest.class);
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
request = new MockHttpServletRequest();
response = new MockHttpServletResponse();
}
@After
public void tearDown() throws Exception {
}
@Test
public void testAvailable1() throws Exception {
logger.debug("Start testAvailable2");
logger.debug("Test only availibility of the apps");
request.setMethod("GET");
request.setRequestURI("/available.html");
final Object handler = handlerMapping.getHandler(request).getHandler();
logger.debug("Get the Model and View");
final ModelAndView mav = (ModelAndView) handlerAdapter.handle(request, response,handler);
final Map<String, Object> model = mav.getModel();
Assert.assertEquals(model.get("sample"),"availability on 0.0.1");
Assert.assertTrue(model.containsKey("sample"));
Assert.assertEquals("available", mav.getViewName());
Assert.assertTrue(mav instanceof ModelAndView);
final BindingResult result = mock(BindingResult.class);
when(result.hasErrors()).thenReturn(true);
logger.debug("End testAvailable2");
}
@Test
public void testAvailable2() throws Exception {
logger.debug("Start testAvailable2");
logger.debug("Test only availibility of the apps");
request.setMethod("GET");
request.setRequestURI("/available.html");
final Object handler = handlerMapping.getHandler(request).getHandler();
logger.debug("Get the Model and View");
final ModelAndView mav = (ModelAndView) handlerAdapter.handle(request, response,handler);
Assert.assertEquals(200, response.getStatus());
ModelAndViewAssert.assertAndReturnModelAttributeOfType(mav, "sample", String.class);
ModelAndViewAssert.assertModelAttributeAvailable(mav, "sample");
ModelAndViewAssert.assertModelAttributeValue(mav, "sample", "availability on 0.0.1");
ModelAndViewAssert.assertViewName(mav, "available");
logger.debug("End testAvailable");
}
public void testAvailable3() throws Exception {
AvailibilityController c = new AvailibilityController();
final Object mav = c.available(request);
Assert.assertTrue(mav instanceof ModelAndView);
}
} |
Partager