Methods Summary |
---|
public com.opensymphony.xwork2.Action | getAction()
TestAction action = new TestAction();
action.setFoo(fooValue);
return action;
|
private java.util.Locale | getDefaultLocale()
if (Locale.getDefault().getLanguage().equals("de")) {
return Locale.GERMANY;
} else if (Locale.getDefault().getLanguage().equals("fr")) {
return Locale.FRANCE;
} else {
return Locale.US;
}
|
private java.util.Locale | getForeignLocale()
if (Locale.getDefault().getLanguage().equals("de")) {
return Locale.FRANCE;
} else {
return Locale.GERMANY;
}
|
private java.lang.String | getLocalizedMessage(java.util.Locale locale)
if (locale.getLanguage().equals("de")) {
return "This is TestBean1 in German";
} else if (locale.getLanguage().equals("fr")) {
return "This is TestBean1 in French";
} else {
return "This is TestBean1";
}
|
protected void | setUp()todo remove ActionContext set after LocalizedTextUtil is fixed to not use ThreadLocal
super.setUp();
tag = new TextTag();
tag.setPageContext(pageContext);
ActionContext.setContext(new ActionContext(stack.getContext()));
|
protected void | tearDown()
ValueStack valueStack = ValueStackFactory.getFactory().createValueStack();
ActionContext.setContext(new ActionContext(valueStack.getContext()));
|
public void | testBlankNameDefined()
tag.setName("");
tag.doStartTag();
tag.doEndTag();
assertEquals("", writer.toString());
|
public void | testCorrectI18NKey()
String key = "foo.bar.baz";
String value = "This should start with foo";
tag.setName(key);
tag.doStartTag();
tag.doEndTag();
assertEquals(value, writer.toString());
|
public void | testCorrectI18NKey2()
String key = "bar.baz";
String value = "No foo here";
tag.setName(key);
tag.doStartTag();
tag.doEndTag();
assertEquals(value, writer.toString());
|
public void | testDefaultMessageOk()
// NOTE:
// simulate the condition
// <s:text name="some.invalid.key">My Default Message</s:text>
StrutsMockBodyContent mockBodyContent = new StrutsMockBodyContent(new MockJspWriter());
mockBodyContent.setString("Sample Of Default Message");
tag.setBodyContent(mockBodyContent);
tag.setName("some.invalid.key.so.we.should.get.the.default.message");
int startStatus = tag.doStartTag();
tag.doEndTag();
assertEquals(startStatus, BodyTag.EVAL_BODY_BUFFERED);
assertEquals("Sample Of Default Message", writer.toString());
|
public void | testExpressionsEvaluated()
String key = "expressionKey";
String value = "Foo is " + fooValue;
tag.setName(key);
tag.doStartTag();
tag.doEndTag();
assertEquals(value, writer.toString());
|
public void | testMessageFormatWorks()
String key = "messageFormatKey";
String pattern = "Params are {0} {1} {2}";
Object param1 = new Integer(12);
Object param2 = new Date();
Object param3 = "StringVal";
List params = new ArrayList();
params.add(param1);
params.add(param2);
params.add(param3);
String expected = MessageFormat.format(pattern, params.toArray());
tag.setName(key);
tag.doStartTag();
((Text) tag.component).addParameter(param1);
((Text) tag.component).addParameter(param2);
((Text) tag.component).addParameter(param3);
tag.doEndTag();
assertEquals(expected, writer.toString());
|
public void | testNoNameDefined()
String msg = "tag 'text', field 'name': You must specify the i18n key. Example: welcome.header";
try {
tag.doStartTag();
tag.doEndTag();
fail("Should have thrown a RuntimeException");
} catch (StrutsException e) {
assertEquals(msg, e.getMessage());
}
|
public void | testPutId()
assertEquals(null, stack.findString("myId")); // nothing in stack
tag.setId("myId");
tag.setName("bar.baz");
tag.doStartTag();
tag.doEndTag();
assertEquals("", writer.toString());
assertEquals("No foo here", stack.findString("myId")); // is in stack now
|
public void | testSimpleKeyValueWorks()
String key = "simpleKey";
String value = "Simple Message";
tag.setName(key);
tag.doStartTag();
tag.doEndTag();
assertEquals(value, writer.toString());
|
public void | testTextTagUsesLocaleFromValueStack()
stack.pop();
stack.push(new TestAction1());
Locale defaultLocale = getDefaultLocale();
Locale foreignLocale = getForeignLocale();
assertNotSame(defaultLocale, foreignLocale);
ActionContext.getContext().setLocale(defaultLocale);
String key = "simpleKey";
String value_default = getLocalizedMessage(defaultLocale);
tag.setName(key);
tag.doStartTag();
tag.doEndTag();
assertEquals(value_default, writer.toString());
final StringBuffer buffer = writer.getBuffer();
buffer.delete(0, buffer.length());
String value_int = getLocalizedMessage(foreignLocale);
assertFalse(value_default.equals(value_int));
ValueStack newStack = ValueStackFactory.getFactory().createValueStack(stack);
newStack.getContext().put(ActionContext.LOCALE, foreignLocale);
assertNotSame(newStack.getContext().get(ActionContext.LOCALE), ActionContext.getContext().getLocale());
request.setAttribute(ServletActionContext.STRUTS_VALUESTACK_KEY, newStack);
assertEquals(ActionContext.getContext().getValueStack().peek(), newStack.peek());
tag.doStartTag();
tag.doEndTag();
assertEquals(value_int, writer.toString());
|
public void | testTextTagUsesValueStackInRequestNotActionContext()
String key = "simpleKey";
String value1 = "Simple Message";
Locale foreignLocale = getForeignLocale();
String value2 = getLocalizedMessage(foreignLocale);
tag.setName(key);
tag.doStartTag();
tag.doEndTag();
assertEquals(value1, writer.toString());
final StringBuffer buffer = writer.getBuffer();
buffer.delete(0, buffer.length());
ValueStack newStack = ValueStackFactory.getFactory().createValueStack();
newStack.getContext().put(ActionContext.LOCALE, foreignLocale);
newStack.push(new TestAction1());
request.setAttribute(ServletActionContext.STRUTS_VALUESTACK_KEY, newStack);
assertNotSame(ActionContext.getContext().getValueStack().peek(), newStack.peek());
tag.doStartTag();
tag.doEndTag();
assertEquals(value2, writer.toString());
|
public void | testWithNoMessageAndBodyIsNotEmptyBodyIsReturned()
final String key = "key.does.not.exist";
final String bodyText = "body text";
tag.setName(key);
StrutsBodyContent bodyContent = new StrutsBodyContent(null);
bodyContent.print(bodyText);
tag.setBodyContent(bodyContent);
tag.doStartTag();
tag.doEndTag();
assertEquals(bodyText, writer.toString());
|
public void | testWithNoMessageAndNoDefaultKeyReturned()
final String key = "key.does.not.exist";
tag.setName("'" + key + "'");
tag.doStartTag();
tag.doEndTag();
assertEquals(key, writer.toString());
|