001: package com.sun.portal.desktop.test;
002:
003: import com.sun.portal.providers.context.ContainerProviderContext;
004:
005: import com.sun.portal.providers.ProviderAdapter;
006: import com.sun.portal.providers.Provider;
007: import com.sun.portal.providers.ProviderEditTypes;
008: import com.sun.portal.providers.ProviderWidths;
009: import com.sun.portal.providers.ProviderException;
010: import com.sun.portal.providers.UnknownEditTypeException;
011:
012: import com.sun.portal.desktop.context.DesktopAppContextThreadLocalizer;
013: import com.sun.portal.desktop.context.DesktopAppContext;
014:
015: import junit.framework.TestCase;
016: import junit.framework.Test;
017: import junit.framework.TestSuite;
018: import junit.framework.AssertionFailedError;
019:
020: import javax.servlet.http.HttpServletRequest;
021: import javax.servlet.http.HttpServletResponse;
022:
023: import java.net.URL;
024:
025: public class ProviderAdapterTest extends TestCase implements
026: ProviderEditTypes, ProviderWidths {
027: protected Provider provider = null;
028: protected HttpServletRequest req = null;
029: protected HttpServletResponse res = null;
030: protected DesktopAppContext appContext = null;
031:
032: public ProviderAdapterTest(Provider p, HttpServletRequest req,
033: HttpServletResponse res, String test) {
034: super (test);
035:
036: this .provider = p;
037: this .req = req;
038: this .res = res;
039:
040: appContext = DesktopAppContextThreadLocalizer.get();
041: }
042:
043: public static TestSuite suite(ContainerProviderContext cpc,
044: HttpServletRequest req, HttpServletResponse res) {
045: Provider p = cpc.getProvider(req, null, "test1");
046:
047: TestSuite ts = new TestSuite();
048:
049: ts.addTest(new ProviderAdapterTest(p, req, res,
050: "testProviderNotNull"));
051: ts.addTest(new ProviderAdapterTest(p, req, res, "testGetName"));
052: ts
053: .addTest(new ProviderAdapterTest(p, req, res,
054: "testGetTitle"));
055: ts.addTest(new ProviderAdapterTest(p, req, res,
056: "testGetDescription"));
057: ts.addTest(new ProviderAdapterTest(p, req, res,
058: "testGetRefreshTime"));
059: ts.addTest(new ProviderAdapterTest(p, req, res,
060: "testIsEditable"));
061: ts.addTest(new ProviderAdapterTest(p, req, res,
062: "testGetEditType"));
063: ts
064: .addTest(new ProviderAdapterTest(p, req, res,
065: "testGetWidth"));
066: ts.addTest(new ProviderAdapterTest(p, req, res, "testGetHelp"));
067:
068: return ts;
069: }
070:
071: public void testProviderNotNull() {
072: assertNotNull(provider);
073: }
074:
075: public void testGetName() throws ProviderException {
076: String name = provider.getName();
077: assertNotNull(name);
078: }
079:
080: public void testGetTitle() throws ProviderException {
081: String title = provider.getTitle();
082: assertNotNull(title);
083: }
084:
085: public void testGetDescription() throws ProviderException {
086: String desc = provider.getDescription();
087: assertNotNull(desc);
088: }
089:
090: public void testGetHelp() {
091: try {
092: URL hu = provider.getHelp(req);
093: assertNotNull("returned null unexpectedly", hu);
094: } catch (ProviderException pe) {
095: //appContext.debugError(pe);
096: throw new AssertionFailedError(pe.getMessage());
097: }
098: }
099:
100: public void testGetRefreshTime() throws ProviderException {
101: long rt = provider.getRefreshTime();
102: assertTrue(rt > -1);
103: }
104:
105: public void testIsEditable() throws ProviderException {
106: boolean e = provider.isEditable();
107: assertTrue(!e);
108: }
109:
110: public void testGetEditType() throws UnknownEditTypeException {
111: int et = provider.getEditType();
112: boolean valid = (et == EDIT_SUBSET) || (et == EDIT_COMPLETE);
113:
114: assertTrue(valid);
115: }
116:
117: public void testGetWidth() throws ProviderException {
118: int w = provider.getWidth();
119: boolean valid = (w == WIDTH_THICK) || (w == WIDTH_THIN)
120: || (w == WIDTH_FULL_TOP) || (w == WIDTH_FULL_BOTTOM);
121:
122: assertTrue(valid);
123: }
124:
125: }
|