@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>
Application.
@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");
}
| Modifier and Type | Class and Description |
|---|---|
protected class |
TestBase.ActionCall
|
protected class |
TestBase.DataSourceCall
A wrapper for a
DatasourceRef, allowing to add Parameters and to retrieve the actual
CallableDataSource. |
protected class |
TestBase.SimpleApplication |
protected class |
TestBase.SimpleFeatureProvider |
| 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 and Description |
|---|
TestBase() |
TestBase(String name) |
TestBase(String applicationName,
String applicationLocation) |
| 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)
|
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 a
HandlerMethodArgumentResolver that can resolve a(n)
Environment
Site
Application
Useful when testing a Controller/ RestController with MockMvc: |
protected List<Property> |
getPlatformProperties(String prefix) |
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 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,
DifferenceListener differenceListener) |
void |
validate(BaseObject object,
String suffix) |
void |
validate(BaseObject object,
String suffix,
DifferenceListener differenceListener) |
public static final String TESTCONTEXT
public static final String TESTCONTEXT_CORE
public static final String TESTCONTEXT_JPA
public static final String BEANS_PATH
protected static final String APPLICATION_HOME
protected static final String FORM_ACTION
@Autowired protected javax.servlet.ServletContext servletContext
protected javax.servlet.http.HttpSession session
@Autowired protected org.springframework.mock.web.MockHttpServletRequest servletRequest
@Autowired protected org.springframework.mock.web.MockHttpServletResponse servletResponse
@Autowired protected org.springframework.context.ConfigurableApplicationContext context
@Autowired protected org.springframework.context.MessageSource messageSource
@Autowired protected org.springframework.core.convert.ConversionService conversionService
@Autowired protected MarshallService marshallService
protected Environment environment
protected ApplicationRequest request
protected Application application
protected Site site
@Mock protected Subject subject
@Mock protected Path path
public TestBase()
public TestBase(String name)
protected void subjectWithRole(String roleName)
public void initialize(org.springframework.context.support.GenericApplicationContext applicationContext)
initialize in interface org.springframework.context.ApplicationContextInitializer<org.springframework.context.support.GenericApplicationContext>protected void mockSite(org.springframework.context.support.GenericApplicationContext applicationContext)
protected Application mockApplication(org.springframework.context.support.GenericApplicationContext applicationContext)
protected Resources getApplicationResources(MarshallService applicationMarshallService)
protected Resources mockResources()
protected Properties getProperties()
Properties used by
ApplicationContextInitializer.initialize(ConfigurableApplicationContext) and also for the
Application's properties. Override in subclasses to add custom values.Application.getProperties(),
initialize(GenericApplicationContext)protected void addParameter(String name, String value)
Request used in the testcase.initParameters() (or initParameters(boolean)) has to be
called.TestBase.DataSourceCall.withParam(String, String) and
TestBase.ActionCall.withParam(String, String)!name - the name of the parametervalue - the value of the parameterprotected FormUpload getFormUpload(String resourceName) throws URISyntaxException
URISyntaxExceptionprotected List<ApplicationSubject> getApplicationSubjects()
protected void initRequest()
throws InvalidConfigurationException,
JAXBException
protected void initParameters()
Request for the testcase. Before, some paramters can be added using
addParameter(String, String)protected void initParameters(boolean isPost)
protected void init(boolean isPost)
protected void initEnvironment()
public void validate(BaseObject object) throws IOException
IOExceptionpublic void validate(BaseObject object, DifferenceListener differenceListener) throws IOException
IOExceptionpublic void validate(BaseObject object, String suffix, DifferenceListener differenceListener) throws IOException
IOExceptionpublic void validate(BaseObject object, String suffix) throws IOException
IOExceptionprotected String getEntityPackage()
protected void setEntityPackage(String entityPackage)
protected String getRepositoryBase()
protected void setRepositoryBase(String repositoryBase)
protected boolean isUseFullClassname()
protected void setUseFullClassname(boolean useFullClassname)
protected TestBase.DataSourceCall getDataSource(String id)
id - the id of the DatasourceTestBase.DataSourceCallprotected TestBase.ActionCall getAction(String eventId, String id)
eventId - the id of the Eventid - the id of the ActionTestBase.ActionCallpublic org.springframework.web.method.support.HandlerMethodArgumentResolver getHandlerMethodArgumentResolver()
HandlerMethodArgumentResolver that can resolve a(n)
Useful when testing a Controller/ RestController with MockMvc:
MockMvc mockMvc = MockMvcBuilders.standaloneSetup(context.getBean(MyRestController.class))
.setCustomArgumentResolvers(getHandlerMethodArgumentResolver()).build();
Copyright © 2011–2022 aiticon GmbH. All rights reserved.