Package 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 anApplication
.
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"); } }
TestingActionProvider
s andDataProvider
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 Description protected class
TestBase.ActionCall
protected class
TestBase.DataSourceCall
A wrapper for aDatasourceRef
, allowing to addParam
eters and to retrieve the actualCallableDataSource
.protected class
TestBase.SimpleApplication
protected class
TestBase.SimpleFeatureProvider
-
Field Summary
Fields Modifier and Type Field 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
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
addParameter(String name, String value)
Adds a parameter to theRequest
used in the testcase.
After all parameters have been added,initParameters()
(orinitParameters(boolean)
) has to be called.
Not to confiuse withTestBase.DataSourceCall.withParam(String, String)
andTestBase.ActionCall.withParam(String, String)
!protected TestBase.ActionCall
getAction(String eventId, String id)
protected Resources
getApplicationResources(MarshallService applicationMarshallService)
protected List<ApplicationSubject>
getApplicationSubjects()
protected TestBase.DataSourceCall
getDataSource(String id)
protected String
getEntityPackage()
protected FormUpload
getFormUpload(String resourceName)
org.springframework.web.method.support.HandlerMethodArgumentResolver
getHandlerMethodArgumentResolver()
Returns aHandlerMethodArgumentResolver
that can resolve a(n)Environment
Site
Application
Useful when testing aController
/RestController
withMockMvc
:protected List<Property>
getPlatformProperties(String prefix)
protected Properties
getProperties()
Returns theProperties
used byApplicationContextInitializer.initialize(ConfigurableApplicationContext)
and also for theApplication
'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 theRequest
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, String suffix)
void
validate(BaseObject object, String suffix, DifferenceListener differenceListener)
void
validate(BaseObject object, DifferenceListener differenceListener)
-
-
-
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
-
-
Method Detail
-
subjectWithRole
protected void subjectWithRole(String roleName)
-
initialize
public void initialize(org.springframework.context.support.GenericApplicationContext applicationContext)
- Specified by:
initialize
in interfaceorg.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 theProperties
used byApplicationContextInitializer.initialize(ConfigurableApplicationContext)
and also for theApplication
'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 theRequest
used in the testcase.
After all parameters have been added,initParameters()
(orinitParameters(boolean)
) has to be called.
Not to confiuse withTestBase.DataSourceCall.withParam(String, String)
andTestBase.ActionCall.withParam(String, String)
!- Parameters:
name
- the name of the parametervalue
- the value of the parameter
-
getFormUpload
protected FormUpload getFormUpload(String resourceName) throws URISyntaxException
- Throws:
URISyntaxException
-
getApplicationSubjects
protected List<ApplicationSubject> getApplicationSubjects()
-
initRequest
protected void initRequest() throws InvalidConfigurationException, JAXBException
-
initParameters
protected void initParameters()
Initializes theRequest
for the testcase. Before, some paramters can be added usingaddParameter(String, String)
-
initParameters
protected void initParameters(boolean isPost)
-
init
protected void init(boolean isPost)
-
initEnvironment
protected void initEnvironment()
-
validate
public void validate(BaseObject object) throws IOException
- Throws:
IOException
-
validate
public void validate(BaseObject object, DifferenceListener differenceListener) throws IOException
- Throws:
IOException
-
validate
public void validate(BaseObject object, String suffix, 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)
- Parameters:
id
- the id of theDatasource
- Returns:
- the
TestBase.DataSourceCall
-
getAction
protected TestBase.ActionCall getAction(String eventId, String id)
- Parameters:
eventId
- the id of theEvent
id
- the id of theAction
- Returns:
- the
TestBase.ActionCall
-
getHandlerMethodArgumentResolver
public org.springframework.web.method.support.HandlerMethodArgumentResolver getHandlerMethodArgumentResolver()
Returns aHandlerMethodArgumentResolver
that can resolve a(n) Useful when testing aController
/RestController
withMockMvc
:MockMvc mockMvc = MockMvcBuilders.standaloneSetup(context.getBean(MyRestController.class)) .setCustomArgumentResolvers(getHandlerMethodArgumentResolver()).build();
- Returns:
- the resolver
-
-