📄 testforwardconfig.java
字号:
* Test checkCircularInheritance() for circular inheritance between a
* forward declared in an action and a global forward.
*/
public void testCheckCircularInheritanceActionForwardExtendGlobal() {
actionConfig.addForwardConfig(subConfig);
moduleConfig.addForwardConfig(baseConfig);
boolean result =
subConfig.checkCircularInheritance(moduleConfig, actionConfig);
assertTrue("Incorrect result", !result);
}
/**
* Test checkCircularInheritance() for circular inheritance between a
* forward declared in an action and a global forward and both forwards
* have the same name.
*/
public void testCheckCircularInheritanceActionForwardExtendGlobalSameName() {
moduleConfig.addForwardConfig(baseConfig);
actionConfig.addForwardConfig(actionBaseConfig);
boolean result =
actionBaseConfig.checkCircularInheritance(moduleConfig, actionConfig);
assertTrue("Incorrect result", !result);
}
/**
* Make sure processExtends() throws an error when the config is already
* configured.
*/
public void testProcessExtendsConfigured()
throws Exception {
baseConfig.configured = true;
moduleConfig.addForwardConfig(baseConfig);
try {
baseConfig.processExtends(moduleConfig, null);
fail(
"processExtends should not succeed when object is already configured");
} catch (IllegalStateException e) {
// success
}
}
/**
* Test processExtends() when nothing is extended.
*/
public void testProcessExtendsNoExtension()
throws Exception {
String path = baseConfig.getPath();
String module = baseConfig.getModule();
String name = baseConfig.getName();
String inherit = baseConfig.getExtends();
boolean redirect = baseConfig.getRedirect();
moduleConfig.addForwardConfig(baseConfig);
baseConfig.processExtends(moduleConfig, null);
assertEquals("Path shouldn't have changed", path, baseConfig.getPath());
assertEquals("Module shouldn't have changed", module,
baseConfig.getModule());
assertEquals("Name shouldn't have changed", name, baseConfig.getName());
assertEquals("Extends shouldn't have changed", inherit,
baseConfig.getExtends());
assertEquals("Redirect shouldn't have changed", redirect,
baseConfig.getRedirect());
}
/**
* Test processExtends() with a basic extension.
*/
public void testProcessExtendsBasicExtension()
throws Exception {
String baseCount = "10";
baseConfig.setProperty("count", baseCount);
String baseLabel = "label a";
baseConfig.setProperty("label", baseLabel);
String path = baseConfig.getPath();
String module = baseConfig.getModule();
String inherit = subConfig.getExtends();
String name = subConfig.getName();
boolean redirect = subConfig.getRedirect();
String subLabel = "label b";
subConfig.setProperty("label", subLabel);
moduleConfig.addForwardConfig(baseConfig);
moduleConfig.addForwardConfig(subConfig);
subConfig.processExtends(moduleConfig, null);
assertEquals("Path wasn't inherited", path, subConfig.getPath());
assertEquals("Module wasn't inherited", module, subConfig.getModule());
assertEquals("Name shouldn't have changed", name, subConfig.getName());
assertEquals("Extends shouldn't have changed", inherit,
subConfig.getExtends());
assertEquals("Redirect shouldn't have changed", redirect,
subConfig.getRedirect());
assertEquals("Arbitrary config property was not inherited", baseCount,
subConfig.getProperty("count"));
assertEquals("Overridden config property was not retained", subLabel,
subConfig.getProperty("label"));
}
/**
* Test processExtends() with a basic extension between an action config
* and a global config.
*/
public void testProcessExtendsBasicGlobalExtension()
throws Exception {
String path = baseConfig.getPath();
String module = baseConfig.getModule();
boolean redirect = subConfig.getRedirect();
String inherit = subConfig.getExtends();
String name = subConfig.getName();
moduleConfig.addForwardConfig(baseConfig);
actionConfig.addForwardConfig(subConfig);
subConfig.processExtends(moduleConfig, actionConfig);
assertEquals("Path wasn't inherited", path, subConfig.getPath());
assertEquals("Module wasn't inherited", module, subConfig.getModule());
assertEquals("Name shouldn't have changed", name, subConfig.getName());
assertEquals("Extends shouldn't have changed", inherit,
subConfig.getExtends());
assertEquals("Redirect shouldn't have changed", redirect,
subConfig.getRedirect());
}
/**
* Test processExtends() with an incorrect setup where a global config
* attempts to extend an action config.
*/
public void testProcessExtendsGlobalExtendingAction()
throws Exception {
moduleConfig.addForwardConfig(subConfig);
actionConfig.addForwardConfig(baseConfig);
try {
subConfig.processExtends(moduleConfig, actionConfig);
fail(
"Should not find config from actionConfig when *this* is global");
} catch (NullPointerException npe) {
// succeed
}
}
/**
* Test processExtends() with an action config that extends a global
* config with the same name.
*/
public void testProcessExtendsSameNames()
throws Exception {
String path = baseConfig.getPath();
boolean redirect = baseConfig.getRedirect();
String module = actionBaseConfig.getModule();
String inherit = actionBaseConfig.getExtends();
String name = actionBaseConfig.getName();
moduleConfig.addForwardConfig(baseConfig);
actionConfig.addForwardConfig(actionBaseConfig);
actionBaseConfig.processExtends(moduleConfig, actionConfig);
assertEquals("Path wasn't inherited", path, actionBaseConfig.getPath());
assertEquals("Module shouldn't have changed", module,
actionBaseConfig.getModule());
assertEquals("Name shouldn't have changed", name,
actionBaseConfig.getName());
assertEquals("Extends shouldn't have changed", inherit,
actionBaseConfig.getExtends());
assertEquals("Redirect shouldn't have changed", redirect,
actionBaseConfig.getRedirect());
}
/**
* Test processExtends() where an action ForwardConfig extends another
* ForwardConfig, which in turn extends a global ForwardConfig with the
* same name.
*/
public void testProcessExtendsActionExtendsActionExtendsGlobalWithSameName()
throws Exception {
String path = baseConfig.getPath();
String module = actionBaseConfig.getModule();
boolean redirect = subConfig.getRedirect();
String inherit = subConfig.getExtends();
String name = subConfig.getName();
moduleConfig.addForwardConfig(baseConfig);
actionConfig.addForwardConfig(actionBaseConfig);
actionConfig.addForwardConfig(subConfig);
subConfig.processExtends(moduleConfig, actionConfig);
assertTrue("baseConfig's processExtends() should've been called",
baseConfig.extensionProcessed);
assertTrue("actionBaseConfig's processExtends() should've been called",
actionBaseConfig.extensionProcessed);
assertEquals("Path wasn't inherited", path, subConfig.getPath());
assertEquals("Module wasn't inherited", module, subConfig.getModule());
assertEquals("Name shouldn't have changed", name, subConfig.getName());
assertEquals("Extends shouldn't have changed", inherit,
subConfig.getExtends());
assertEquals("Redirect shouldn't have changed", redirect,
subConfig.getRedirect());
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -