001: package com.sun.portal.desktop.test;
002:
003: import com.sun.portal.providers.context.ProviderContext;
004: import com.sun.portal.providers.context.ProviderContextException;
005:
006: import com.sun.portal.desktop.context.DesktopAppContextThreadLocalizer;
007: import com.sun.portal.desktop.context.DesktopAppContext;
008:
009: import junit.framework.TestCase;
010: import junit.framework.Test;
011: import junit.framework.TestSuite;
012:
013: import java.io.File;
014:
015: public class ProviderContextTest extends TestCase {
016: protected ProviderContext providerContext = null;
017:
018: public ProviderContextTest(ProviderContext pc, String test) {
019: super (test);
020: providerContext = pc;
021: }
022:
023: public static TestSuite suite(ProviderContext pc) {
024: TestSuite ts = new TestSuite();
025:
026: ts.addTest(new ProviderContextTest(pc,
027: "testProviderContextNotNull"));
028: ts.addTest(new ProviderContextTest(pc, "testGetLocaleString"));
029: ts.addTest(new ProviderContextTest(pc,
030: "testGetStringPropertyFromChannel"));
031: ts.addTest(new ProviderContextTest(pc,
032: "testGetStringPropertyFromProvider"));
033: ts
034: .addTest(new ProviderContextTest(pc,
035: "testGetSessionProperty"));
036: ts.addTest(new ProviderContextTest(pc,
037: "testGetTemplateMostSpecificPath"));
038: ts.addTest(new ProviderContextTest(pc, "testGetTemplatePath"));
039:
040: return ts;
041: }
042:
043: public void testProviderContextNotNull() {
044: assertNotNull(providerContext);
045: }
046:
047: public void testGetLocaleString() throws ProviderContextException {
048: assertEquals(providerContext.getLocaleString(), "en_US");
049: }
050:
051: public void testGetStringPropertyFromChannel()
052: throws ProviderContextException {
053: String a = providerContext.getStringProperty("test1", "a");
054: assertEquals(a, "as");
055: String b = providerContext.getStringProperty("test1", "b");
056: assertEquals(b, "bs");
057: String c = providerContext.getStringProperty("test1", "c");
058: assertEquals(c, "cs");
059: }
060:
061: public void testGetStringPropertyFromProvider()
062: throws ProviderContextException {
063: String ap = providerContext.getStringProperty("test1", "ap");
064: assertEquals(ap, "asp");
065: String bp = providerContext.getStringProperty("test1", "bp");
066: assertEquals(bp, "bsp");
067: String cp = providerContext.getStringProperty("test1", "cp");
068: assertEquals(cp, "csp");
069: }
070:
071: public void testGetSessionProperty()
072: throws ProviderContextException {
073: String x = "xxx";
074: providerContext.setSessionProperty("x", x);
075: String xt = (String) providerContext.getSessionProperty("x");
076: assertNotNull(xt);
077: assertEquals(xt, "xxx");
078: }
079:
080: public void testGetTemplateMostSpecificPath()
081: throws ProviderContextException {
082: DesktopAppContext dac = DesktopAppContextThreadLocalizer.get();
083: String baseDir = dac.getTemplateBaseDir();
084:
085: String desktopType = providerContext.getDesktopType();
086: String locale = providerContext.getLocaleString();
087: String clientPath = providerContext.getClientPath();
088: String name = "test1";
089: String file = "test.html";
090:
091: File file1 = providerContext.getTemplateMostSpecificPath(name,
092: file);
093: File file2 = providerContext.getTemplateMostSpecificPath(
094: desktopType, locale, name, clientPath, file, baseDir);
095:
096: assertEquals(file1.getAbsolutePath(), file2.getAbsolutePath());
097: }
098:
099: public void testGetTemplatePath() throws ProviderContextException {
100: DesktopAppContext dac = DesktopAppContextThreadLocalizer.get();
101: String baseDir = dac.getTemplateBaseDir();
102:
103: String desktopType = providerContext.getDesktopType();
104: String locale = providerContext.getLocaleString();
105: String clientPath = providerContext.getClientPath();
106: String name = "test1";
107: String file = "test.html";
108:
109: File file1 = providerContext.getTemplatePath(name, file);
110: File file2 = providerContext.getTemplatePath(desktopType,
111: locale, name, clientPath, file, baseDir);
112:
113: assertEquals(file1.getAbsolutePath(), file2.getAbsolutePath());
114: }
115:
116: }
|