001: /*
002: * Copyright 2006 The Apache Software Foundation
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.apache.commons.chain.web.portlet;
017:
018: import junit.framework.Test;
019: import junit.framework.TestCase;
020: import junit.framework.TestSuite;
021: import org.apache.commons.chain.Context;
022:
023: import javax.portlet.PortletContext;
024: import javax.portlet.PortletRequest;
025: import javax.portlet.PortletResponse;
026: import javax.portlet.PortletSession;
027: import java.util.Locale;
028:
029: // Test case for org.apache.commons.chain.web.portlet.PortletGetLocaleCommand
030:
031: public class PortletGetLocaleCommandTestCase extends TestCase {
032:
033: // ---------------------------------------------------------- Constructors
034:
035: /**
036: * Construct a new instance of this test case.
037: *
038: * @param name Name of the test case
039: */
040: public PortletGetLocaleCommandTestCase(String name) {
041: super (name);
042: }
043:
044: // ----------------------------------------------------- Instance Variables
045:
046: protected Locale locale = null;
047:
048: // Portlet API Objects
049: protected PortletContext pcontext = null;
050: protected PortletRequest request = null;
051: protected PortletResponse response = null;
052: protected PortletSession session = null;
053:
054: // Chain API Objects
055: protected Context context = null;
056: protected PortletGetLocaleCommand command = null;
057:
058: // -------------------------------------------------- Overall Test Methods
059:
060: /**
061: * Set up instance variables required by this test case.
062: */
063: public void setUp() {
064:
065: locale = new Locale("en", "US");
066:
067: // Set up Portlet API Objects
068: pcontext = new MockPortletContext();
069: session = new MockPortletSession(pcontext);
070: request = new MockPortletRequest(null, pcontext, session);
071: ((MockPortletRequest) request).setLocale(locale);
072:
073: // Set up Chain API Objects
074: context = new PortletWebContext(pcontext, request, response);
075: command = new PortletGetLocaleCommand();
076:
077: }
078:
079: /**
080: * Return the tests included in this test suite.
081: */
082: public static Test suite() {
083:
084: return (new TestSuite(PortletGetLocaleCommandTestCase.class));
085:
086: }
087:
088: /**
089: * Tear down instance variables required by this test case.
090: */
091: public void tearDown() {
092:
093: pcontext = null;
094: session = null;
095: request = null;
096: response = null;
097:
098: context = null;
099: command = null;
100:
101: }
102:
103: // ------------------------------------------------- Individual Test Methods
104:
105: // Test configured behavior
106: public void testConfigured() throws Exception {
107:
108: command.setLocaleKey("special");
109: assertEquals("special", command.getLocaleKey());
110: check(context, command);
111:
112: }
113:
114: // Test default behavior
115: public void testDefaut() throws Exception {
116:
117: assertEquals("locale", command.getLocaleKey());
118: check(context, command);
119:
120: }
121:
122: // --------------------------------------------------------- Support Methods
123:
124: protected void check(Context context,
125: PortletGetLocaleCommand command) throws Exception {
126:
127: String localeKey = command.getLocaleKey();
128: assertNotNull(localeKey);
129: Object value = context.get(localeKey);
130: assertNull(value);
131: boolean result = command.execute(context);
132: assertFalse(result);
133: value = context.get(localeKey);
134: assertNotNull(value);
135: assertTrue(value instanceof Locale);
136: assertEquals(locale, (Locale) value);
137:
138: }
139:
140: }
|