001: /***************************************************************
002: * This file is part of the [fleXive](R) project.
003: *
004: * Copyright (c) 1999-2007
005: * UCS - unique computing solutions gmbh (http://www.ucs.at)
006: * All rights reserved
007: *
008: * The [fleXive](R) project is free software; you can redistribute
009: * it and/or modify it under the terms of the GNU General Public
010: * License as published by the Free Software Foundation;
011: * either version 2 of the License, or (at your option) any
012: * later version.
013: *
014: * The GNU General Public License can be found at
015: * http://www.gnu.org/copyleft/gpl.html.
016: * A copy is found in the textfile GPL.txt and important notices to the
017: * license from the author are found in LICENSE.txt distributed with
018: * these libraries.
019: *
020: * This library is distributed in the hope that it will be useful,
021: * but WITHOUT ANY WARRANTY; without even the implied warranty of
022: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
023: * GNU General Public License for more details.
024: *
025: * For further information about UCS - unique computing solutions gmbh,
026: * please see the company website: http://www.ucs.at
027: *
028: * For further information about [fleXive](R), please see the
029: * project website: http://www.flexive.org
030: *
031: *
032: * This copyright notice MUST APPEAR in all copies of the file!
033: ***************************************************************/package com.flexive.tests.embedded.jsf.bean;
034:
035: import com.flexive.faces.beans.MessageBean;
036: import com.flexive.shared.exceptions.FxAccountInUseException;
037: import com.flexive.shared.exceptions.FxLoginFailedException;
038: import com.flexive.shared.exceptions.FxLogoutFailedException;
039: import static com.flexive.tests.embedded.FxTestUtils.login;
040: import static com.flexive.tests.embedded.FxTestUtils.logout;
041: import com.flexive.tests.embedded.TestUsers;
042: import org.apache.commons.lang.StringUtils;
043: import org.testng.annotations.AfterClass;
044: import org.testng.annotations.BeforeClass;
045: import org.testng.annotations.Test;
046:
047: /**
048: * @author Daniel Lichtenberger (daniel.lichtenberger@flexive.com), UCS - unique computing solutions gmbh (http://www.ucs.at)
049: */
050: @Test(groups="jsf")
051: public class MessageBeanTest {
052: private static final String KEY_1 = "test.jsf.fxFacesMessage.1";
053: private static final String MSG_1 = "Test message with one parameter: {0}";
054: private MessageBean messageBean;
055:
056: @BeforeClass
057: public void beforeClass() throws FxLoginFailedException,
058: FxAccountInUseException {
059: messageBean = new MessageBean();
060: login(TestUsers.SUPERVISOR);
061: }
062:
063: @AfterClass
064: public void afterClass() throws FxLoginFailedException,
065: FxAccountInUseException, FxLogoutFailedException {
066: logout();
067: }
068:
069: @Test
070: public void getMessageNoArgs() {
071: String message = (String) messageBean.get(KEY_1);
072: assert MSG_1.equals(message) : "Expected: " + MSG_1 + ", got: "
073: + message;
074: }
075:
076: @Test
077: public void getMessageArgsInt() {
078: String message = (String) messageBean.get(KEY_1 + ",42");
079: String expected = StringUtils.replace(MSG_1, "{0}", "42");
080: assert expected.equals(message) : "Expected: " + expected
081: + ", got: " + message;
082: }
083:
084: @Test
085: public void getMessageArgsString() {
086: String message = (String) messageBean.get(KEY_1
087: + ",random,string");
088: String expected = StringUtils.replace(MSG_1, "{0}", "random");
089: assert expected.equals(message) : "Expected: " + expected
090: + ", got: " + message;
091: }
092:
093: @Test
094: public void getMessageArgsEscapedString() {
095: String message = (String) messageBean.get(KEY_1
096: + ",'random string, with comma'");
097: String expected = StringUtils.replace(MSG_1, "{0}",
098: "random string, with comma");
099: assert expected.equals(message) : "Expected: " + expected
100: + ", got: " + message;
101: }
102:
103: @Test
104: public void getMessageArgsElInt() {
105: String message = (String) messageBean.get(KEY_1 + ",#{41+1}");
106: String expected = StringUtils.replace(MSG_1, "{0}", "42");
107: assert expected.equals(message) : "Expected: " + expected
108: + ", got: " + message;
109: }
110:
111: @Test
112: public void getMessageArgsElString() {
113: String message = (String) messageBean.get(KEY_1
114: + ",#{'some string value'}");
115: String expected = StringUtils.replace(MSG_1, "{0}",
116: "some string value");
117: assert expected.equals(message) : "Expected: " + expected
118: + ", got: " + message;
119: }
120:
121: @Test
122: public void getMessageArgsElStringWithComma() {
123: String message = (String) messageBean.get(KEY_1
124: + ",#{'some string value, with comma'}");
125: String expected = StringUtils.replace(MSG_1, "{0}",
126: "some string value, with comma");
127: assert expected.equals(message) : "Expected: " + expected
128: + ", got: " + message;
129: }
130:
131: }
|