1 11 package org.jboss.portal.test.portlet.preferences.spec; 12 13 import org.jboss.portal.junit.result.InvokeURLResult; 14 import org.jboss.portal.junit.result.AssertResult; 15 import org.jboss.portal.junit.Result; 16 import org.jboss.portal.test.portlet.AbstractPortlet; 17 18 import javax.portlet.ActionRequest; 19 import javax.portlet.ActionResponse; 20 import javax.portlet.PortletException; 21 import javax.portlet.PortletSecurityException; 22 import javax.portlet.RenderRequest; 23 import javax.portlet.RenderResponse; 24 import javax.portlet.PortletURL; 25 import javax.portlet.PortletPreferences; 26 import java.io.IOException ; 27 28 32 public class DynamicPreferenceTreatedLikeModifiablePreferencePortlet extends AbstractPortlet 33 { 34 35 public void processAction(final ActionRequest request, ActionResponse response) throws PortletException, PortletSecurityException, IOException 36 { 37 int requestCount = getRequestCount(request); 38 if (requestCount == 1) 39 { 40 AssertResult result = new AssertResult(); 41 result.execute(new AssertResult.Test() 42 { 43 public void run() throws Exception 44 { 45 PortletPreferences prefs = request.getPreferences(); 47 48 assertEquals("other", prefs.getValue("single_pref", "other")); 50 assertEquals(new String []{"other"}, prefs.getValues("multi_pref", new String []{"other"})); 51 52 prefs.setValue("single_pref", "new_single_pref"); 54 prefs.setValues("multi_pref", new String []{"new_multi_pref_value_1","new_multi_pref_value_2"}); 55 56 assertEquals("new_single_pref", prefs.getValue("single_pref", "other")); 58 assertEquals(new String []{"new_multi_pref_value_1","new_multi_pref_value_2"}, prefs.getValues("multi_pref", new String []{"other"})); 59 60 prefs.store(); 62 63 assertEquals("new_single_pref", prefs.getValue("single_pref", "other")); 65 assertEquals(new String []{"new_multi_pref_value_1","new_multi_pref_value_2"}, prefs.getValues("multi_pref", new String []{"other"})); 66 } 67 }); 68 setRequestLocal(request, result); 69 } 70 else if (requestCount == 2) 71 { 72 AssertResult result = (AssertResult)getRequestLocal(request); 73 result.execute(new AssertResult.Test() 74 { 75 public void run() throws Exception 76 { 77 PortletPreferences prefs = request.getPreferences(); 79 80 assertEquals("new_single_pref", prefs.getValue("single_pref", "other")); 82 assertEquals(new String []{"new_multi_pref_value_1","new_multi_pref_value_2"}, prefs.getValues("multi_pref", new String []{"other"})); 83 84 prefs.reset("single_pref"); 86 prefs.reset("multi_pref"); 87 88 assertEquals("other", prefs.getValue("single_pref", "other")); 90 assertEquals(new String []{"other"}, prefs.getValues("multi_pref", new String []{"other"})); 91 92 prefs.store(); 94 95 assertEquals("other", prefs.getValue("single_pref", "other")); 97 assertEquals(new String []{"other"}, prefs.getValues("multi_pref", new String []{"other"})); 98 } 99 }); 100 } 101 else if (requestCount == 3) 102 { 103 AssertResult result = (AssertResult)getRequestLocal(request); 104 result.execute(new AssertResult.Test() 105 { 106 public void run() throws Exception 107 { 108 PortletPreferences prefs = request.getPreferences(); 110 111 assertEquals("other", prefs.getValue("single_pref", "other")); 113 assertEquals(new String []{"other"}, prefs.getValues("multi_pref", new String []{"other"})); 114 } 115 }); 116 } 117 } 118 119 public void render(final RenderRequest request, RenderResponse response) throws PortletException, PortletSecurityException, IOException 120 { 121 Result result = null; 122 int requestCount = getRequestCount(request); 123 if (requestCount >= 0 && requestCount <= 2) 124 { 125 PortletURL url = response.createActionURL(); 126 result = new InvokeURLResult(url.toString()); 127 } 128 else if (requestCount == 3) 129 { 130 result = (Result)getRequestLocal(request); 131 } 132 133 sendResult(response, result); 135 } 136 } 137 | Popular Tags |