Post
1 year ago
spring-mvc spring spring3

Testing with Spring 3

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:/com/domain/app/conf/spring.sb.xml")
public class TestQuickStartController
{
    @Autowired
    private QuickStartController controller;

    @Before
    public void setup()
    {
        // Dependency2 d1 = new Dependency1();
        // Dependency3 d2 = new Dependency2(d1);
        // Dependency3 d3 = new Dependency3(d2);
        // controller = new QuickStartController(d3);
    }

    @SuppressWarnings("unchecked")
    @Test
    public void testQuickStart()
    {
        final Model model = new BindingAwareModelMap();
        final String m1 = "hello";
        final String dest = controller.quickStart(m1, model);

        // test the destination view
        Assert.assertEquals("quickstart/example", dest);

        // test the message in the model
        final String m2 = (String) model.asMap().get("message");
        Assert.assertEquals(m1, m2);

        // test for the user(s)
        final List us = (List) model.asMap().get("users");
        Assert.assertNotNull(us);
        Assert.assertEquals(1, us.size());
    }
}

Loading...