org.appng.testsupport

## Class TestBase

- java.lang.Object
- - org.appng.testsupport.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 `ActionProvider`s and `DataProvider`s 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

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `protected class` | `TestBase.ActionCall` A wrapper for an `ActionRef`, allowing to add `Param`eters and to retrieve the actual `CallableAction`.
    `protected class` | `TestBase.DataSourceCall` A wrapper for a `DatasourceRef`, allowing to add `Param`eters and to retrieve the actual `CallableDataSource`.
    `protected class` | `TestBase.SimpleApplication`
    `protected class` | `TestBase.SimpleFeatureProvider`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected Application` | `application`
    `protected static String` | `APPLICATION_HOME`
    `static String` | `BEANS_PATH`
    `protected org.springframework.context.ConfigurableApplicationContext` | `context`
    `protected org.springframework.core.convert.ConversionService` | `conversionService`
    `protected Environment` | `environment`
    `protected static String` | `FORM_ACTION`
    `protected MarshallService` | `marshallService`
    `protected org.springframework.context.MessageSource` | `messageSource`
    `protected Path` | `path`
    `protected ApplicationRequest` | `request`
    `protected javax.servlet.ServletContext` | `servletContext`
    `protected org.springframework.mock.web.MockHttpServletRequest` | `servletRequest`
    `protected org.springframework.mock.web.MockHttpServletResponse` | `servletResponse`
    `protected javax.servlet.http.HttpSession` | `session`
    `protected Site` | `site`
    `protected Subject` | `subject`
    `static String` | `TESTCONTEXT`
    `static String` | `TESTCONTEXT_CORE`
    `static String` | `TESTCONTEXT_JPA`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `TestBase()`
    `TestBase(String name)`
    `TestBase(String applicationName, String applicationLocation)`

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected void` | `addParameter(String name, String value)` Adds a parameter to the `Request` used in the testcase. After all parameters have been added, `initParameters()` (or `initParameters(boolean)`) has to be called. Not to confiuse with `TestBase.DataSourceCall.withParam(String, String)` and `TestBase.ActionCall.withParam(String, String)`!
    `protected TestBase.ActionCall` | `getAction(String eventId, String id)` Returns an `TestBase.ActionCall` that wraps an `ActionRef`, using the given id for an `Action`.
    `protected Resources` | `getApplicationResources(MarshallService applicationMarshallService)`
    `protected List<ApplicationSubject>` | `getApplicationSubjects()`
    `protected TestBase.DataSourceCall` | `getDataSource(String id)` Returns a `TestBase.DataSourceCall` that wraps a `DatasourceRef`, using the given id for a `Datasource`
    `protected String` | `getEntityPackage()`
    `protected FormUpload` | `getFormUpload(String resourceName)`
    `org.springframework.web.method.support.HandlerMethodArgumentResolver` | `getHandlerMethodArgumentResolver()` Returns a `HandlerMethodArgumentResolver` that can resolve a(n) `Environment` `Site` `Application` Useful when testing a `Controller`/ `RestController` with `MockMvc`:
    `static Properties` | `getPlatformConfig()` Returns the platform's `Properties`.
    `protected static List<Property>` | `getPlatformProperties()` Returns a list of the platform's essential `Property`s.
    `protected List<Property>` | `getPlatformProperties(String prefix)` Deprecated. use `getPlatformProperties()`
    `protected Properties` | `getProperties()` Returns the `Properties` used by `ApplicationContextInitializer.initialize(ConfigurableApplicationContext)` and also for the `Application`'s properties.
    `protected String` | `getRepositoryBase()`
    `protected List<Property>` | `getSiteProperties(String prefix)`
    `protected void` | `init(boolean isPost)`
    `protected void` | `initEnvironment()`
    `void` | `initialize(org.springframework.context.support.GenericApplicationContext applicationContext)`
    `protected void` | `initParameters()` Initializes the `Request` for the testcase.
    `protected void` | `initParameters(boolean isPost)`
    `protected void` | `initRequest()`
    `protected boolean` | `isUseFullClassname()`
    `protected Application` | `mockApplication(org.springframework.context.support.GenericApplicationContext applicationContext)`
    `protected Application` | `mockApplication(org.springframework.context.support.GenericApplicationContext applicationContext, boolean checkResources)`
    `protected Resources` | `mockResources()`
    `protected void` | `mockSite(org.springframework.context.support.GenericApplicationContext applicationContext)`
    `protected void` | `setEntityPackage(String entityPackage)`
    `protected void` | `setRepositoryBase(String repositoryBase)`
    `void` | `setup()`
    `protected void` | `setUseFullClassname(boolean useFullClassname)`
    `protected void` | `subjectWithRole(String roleName)`
    `void` | `validate(BaseObject object)`
    `void` | `validate(BaseObject object, org.custommonkey.xmlunit.DifferenceListener differenceListener)`
    `void` | `validate(BaseObject object, String suffix)`
    `void` | `validate(BaseObject object, String suffix, org.custommonkey.xmlunit.DifferenceListener differenceListener)`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### TESTCONTEXT

          public static final String TESTCONTEXT

      See Also:
        Constant Field Values

    - #### TESTCONTEXT_CORE

          public static final String TESTCONTEXT_CORE

      See Also:
        Constant Field Values

    - #### TESTCONTEXT_JPA

          public static final String TESTCONTEXT_JPA

      See Also:
        Constant Field Values

    - #### BEANS_PATH

          public static final String BEANS_PATH

      See Also:
        Constant Field Values

    - #### APPLICATION_HOME

          protected static final String APPLICATION_HOME

      See Also:
        Constant Field Values

    - #### FORM_ACTION

          protected static final String FORM_ACTION

      See Also:
        Constant Field Values

    - #### servletContext

          @Autowired
          protected javax.servlet.ServletContext servletContext

    - #### session

          protected javax.servlet.http.HttpSession session

    - #### servletRequest

          @Autowired
          protected org.springframework.mock.web.MockHttpServletRequest servletRequest

    - #### servletResponse

          @Autowired
          protected org.springframework.mock.web.MockHttpServletResponse servletResponse

    - #### context

          @Autowired
          protected org.springframework.context.ConfigurableApplicationContext context

    - #### messageSource

          @Autowired
          protected org.springframework.context.MessageSource messageSource

    - #### conversionService

          @Autowired
          protected org.springframework.core.convert.ConversionService conversionService

    - #### marshallService

          @Autowired
          protected MarshallService marshallService

    - #### environment

          protected Environment environment

    - #### request

          protected ApplicationRequest request

    - #### application

          protected Application application

    - #### site

          protected Site site

    - #### subject

          @Mock
          protected Subject subject

    - #### path

          @Mock
          protected Path path

  - ### Constructor Detail

    - #### TestBase

          public TestBase()

    - #### TestBase

          public TestBase(String name)

    - #### TestBase

          public TestBase(String applicationName,
                          String applicationLocation)

  - ### Method Detail

    - #### subjectWithRole

          protected void subjectWithRole(String roleName)

    - #### initialize

          public void initialize(org.springframework.context.support.GenericApplicationContext applicationContext)

      Specified by:
        `initialize` in interface `org.springframework.context.ApplicationContextInitializer<org.springframework.context.support.GenericApplicationContext>`

    - #### mockSite

          protected void mockSite(org.springframework.context.support.GenericApplicationContext applicationContext)

    - #### mockApplication

          protected Application mockApplication(org.springframework.context.support.GenericApplicationContext applicationContext)

    - #### mockApplication

          protected Application mockApplication(org.springframework.context.support.GenericApplicationContext applicationContext,
                                                boolean checkResources)

    - #### getApplicationResources

          protected Resources getApplicationResources(MarshallService applicationMarshallService)

    - #### mockResources

          protected Resources mockResources()

    - #### getProperties

          protected Properties getProperties()

      Returns the `Properties` used by `ApplicationContextInitializer.initialize(ConfigurableApplicationContext)` and also for the `Application`'s properties. Override in subclasses to add custom values.
      Returns:
        the properties to use
      See Also:
        `Application.getProperties()`, `initialize(GenericApplicationContext)`

    - #### addParameter

          protected void addParameter(String name,
                                      String value)

      Adds a parameter to the `Request` used in the testcase.
      After all parameters have been added, `initParameters()` (or `initParameters(boolean)`) has to be called.
      Not to confiuse with `TestBase.DataSourceCall.withParam(String, String)` and `TestBase.ActionCall.withParam(String, String)`!
      Parameters:
        `name` - the name of the parameter
        `value` - the value of the parameter

    - #### getFormUpload

          protected FormUpload getFormUpload(String resourceName)
                                      throws URISyntaxException

      Throws:
        `URISyntaxException`

    - #### setup

          public void setup()
                     throws Exception

      Throws:
        `Exception`

    - #### getApplicationSubjects

          protected List<ApplicationSubject> getApplicationSubjects()

    - #### initRequest

          protected void initRequest()
                              throws InvalidConfigurationException,
                                     JAXBException

      Throws:
        `InvalidConfigurationException`
        `JAXBException`

    - #### initParameters

          protected void initParameters()

      Initializes the `Request` for the testcase. Before, some paramters can be added using `addParameter(String, String)`

    - #### initParameters

          protected void initParameters(boolean isPost)

    - #### init

          protected void init(boolean isPost)

    - #### initEnvironment

          protected void initEnvironment()

    - #### getSiteProperties

          protected List<Property> getSiteProperties(String prefix)

    - #### getPlatformProperties

          @Deprecated
          protected List<Property> getPlatformProperties(String prefix)

      Deprecated. use `getPlatformProperties()`
      Returns a list of the platform's essential `Property`s.
      Parameters:
        `prefix` - the prefix to use
      Returns:
        a list of the platform's `Property`s

    - #### getPlatformProperties

          protected static List<Property> getPlatformProperties()

      Returns a list of the platform's essential `Property`s.
      Returns:
        a list of the platform's `Property`s

    - #### getPlatformConfig

          public static Properties getPlatformConfig()

      Returns the platform's `Properties`.
      Returns:
        the platform's `Properties`

    - #### validate

          public void validate(BaseObject object)
                        throws IOException

      Throws:
        `IOException`

    - #### validate

          public void validate(BaseObject object,
                               org.custommonkey.xmlunit.DifferenceListener differenceListener)
                        throws IOException

      Throws:
        `IOException`

    - #### validate

          public void validate(BaseObject object,
                               String suffix,
                               org.custommonkey.xmlunit.DifferenceListener differenceListener)
                        throws IOException

      Throws:
        `IOException`

    - #### validate

          public void validate(BaseObject object,
                               String suffix)
                        throws IOException

      Throws:
        `IOException`

    - #### getEntityPackage

          protected String getEntityPackage()

    - #### setEntityPackage

          protected void setEntityPackage(String entityPackage)

    - #### getRepositoryBase

          protected String getRepositoryBase()

    - #### setRepositoryBase

          protected void setRepositoryBase(String repositoryBase)

    - #### isUseFullClassname

          protected boolean isUseFullClassname()

    - #### setUseFullClassname

          protected void setUseFullClassname(boolean useFullClassname)

    - #### getDataSource

          protected TestBase.DataSourceCall getDataSource(String id)

      Returns a `TestBase.DataSourceCall` that wraps a `DatasourceRef`, using the given id for a `Datasource`
      Parameters:
        `id` - the id of the `Datasource`
      Returns:
        the `TestBase.DataSourceCall`

    - #### getAction

          protected TestBase.ActionCall getAction(String eventId,
                                                  String id)

      Returns an `TestBase.ActionCall` that wraps an `ActionRef`, using the given id for an `Action`.
      Parameters:
        `eventId` - the id of the `Event`
        `id` - the id of the `Action`
      Returns:
        the `TestBase.ActionCall`

    - #### getHandlerMethodArgumentResolver

          public org.springframework.web.method.support.HandlerMethodArgumentResolver getHandlerMethodArgumentResolver()

      Returns a `HandlerMethodArgumentResolver` that can resolve a(n)
      - `Environment`
      - `Site`
      - `Application`
      Useful when testing a `Controller`/ `RestController` with `MockMvc`:

           MockMvc mockMvc = MockMvcBuilders.standaloneSetup(context.getBean(MyRestController.class))
                          .setCustomArgumentResolvers(getHandlerMethodArgumentResolver()).build();

      Returns:
        the resolver

Copyright © 2011–2023 aiticon GmbH. All rights reserved.