package gov.va.med.srcalc.web;

import javax.naming.NamingException;

import org.hsqldb.jdbc.JDBCDataSource;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.mock.jndi.SimpleNamingContextBuilder;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;

/**
 * <p>Tests the WebApplicationContext.</p>
 * 
 * <p>Note that I'd love to test view rendering here but it requires JSP
 * rendering which is only available in the real Servlet container.
 */
@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
@ContextConfiguration(
        "file:src/main/webapp/WEB-INF/applicationContext.xml")
public class WebConfigIT
{
    @BeforeClass
    public static void setupJndi() throws NamingException
    {
        final SimpleNamingContextBuilder builder =
                SimpleNamingContextBuilder.emptyActivatedContextBuilder();
        final JDBCDataSource dataSource = new JDBCDataSource();
        dataSource.setUrl("jdbc:hsqldb:mem:srcalctest");
        builder.bind("java:comp/env/jdbc/srcalcDB", dataSource);
    }

    /**
     * Simply forces loading of the application context.
     */
    @Test
    public void testWebConfig()
    {
        // If this method executes, it loaded properly.
    }
}

@@ -188,16 +188,79 @@
 unWith;%0A
+import org.springframework.beans.factory.annotation.Autowired;%0A
 import o
@@ -312,24 +312,24 @@
 extBuilder;%0A
-
 import org.s
@@ -514,16 +514,113 @@
 uration;
+%0Aimport org.springframework.web.context.WebApplicationContext;%0A%0Aimport static org.junit.Assert.*;
 %0A%0A/**%0A *
@@ -983,16 +983,64 @@
 figIT%0A%7B%0A
+    @Autowired%0A    WebApplicationContext fWac;%0A%0A
     @Bef
@@ -1592,27 +1592,326 @@
 es, 
-it loaded properly.
+there were no Exceptions while loading the%0A        // Application Context. Also perform some basic inspection of the%0A        // WebApplicationContext to make sure it loaded properly.%0A        assertNotNull(%0A                %22WebApplicationContext should have a ServletContext%22,%0A                fWac.getServletContext());
 %0A   

improve WebConfigIT