Class TestBase

  • All Implemented Interfaces:
    org.springframework.context.ApplicationContextInitializer<org.springframework.context.support.GenericApplicationContext>

    @ContextConfiguration(locations={"file:application-home/beans.xml","classpath:org/appng/testsupport/application-testcontext.xml"})
    @DirtiesContext
    public class TestBase
    extends Object
    implements org.springframework.context.ApplicationContextInitializer<org.springframework.context.support.GenericApplicationContext>
    Base class for integration-testing an Application.
    Example Usage (w/o JPA):
     @org.springframework.test.context.ContextConfiguration(initializers = MyTest.class)
     public class MyTest extends TestBase {
     
            public MyTest() {
                    super("myapplication", "application-home");
            }
     
     }
     
    Example Usage (with JPA):
     @org.springframework.test.context.ContextConfiguration(locations = {
                    TestBase.TESTCONTEXT_JPA }, initializers = MyTest.class)
     public class MyTest extends TestBase {
     
            public MyTest() {
                    super("myapplication", "application-home");
                    setEntityPackage("org.myapplication.domain");
                    setRepositoryBase("org.myapplication.repository");
            }
     
     }
     
    Testing ActionProviders and DataProviders is this simple:
     @org.junit.Test
     public void testShowPersons() throws ProcessingException, IOException {
            addParameter("sortPersons", "name:desc");
            initParameters();
            CallableDataSource datasource = getDataSource("persons").getCallableDataSource();
            datasource.perform("personPage");
            validate(datasource.getDatasource());
     }
     
     @org.junit.Test
     public void testCreatePerson() throws ProcessingException, IOException {
            CallableAction callableAction = getAction("personEvent", "create").withParam(FORM_ACTION, "create")
                            .getCallableAction(new Person("John", "Doe"));
            FieldProcessor fieldProcessor = callableAction.perform();
            validate(callableAction.getAction(), "-action");
            validate(fieldProcessor.getMessages(), "-messages");
     }
     
    Author:
    Matthias Müller