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 ChangesMadeButNotStoredAreDiscardedPortlet extends AbstractPortlet 33 { 34 35 public void processAction(final ActionRequest request, ActionResponse response) throws PortletException, PortletSecurityException, IOException 36 { 37 AssertResult result = new AssertResult(); 38 int requestCount = getRequestCount(request); 39 if (requestCount == 1) 40 { 41 result = new AssertResult(); 42 result.execute(new AssertResult.Test() 43 { 44 public void run() throws Exception 45 { 46 PortletPreferences prefs = request.getPreferences(); 48 49 assertEquals("static_single_pref_value", prefs.getValue("static_single_pref", "other")); 51 assertEquals(new String []{"static_multi_pref_value_1","static_multi_pref_value_2"}, prefs.getValues("static_multi_pref", new String []{"other"})); 52 assertEquals("other", prefs.getValue("dynamic_single_pref", "other")); 53 assertEquals(new String []{"other"}, prefs.getValues("dynamic_multi_pref", new String []{"other"})); 54 55 prefs.setValue("static_single_pref", "new_static_single_pref_value"); 57 prefs.setValues("static_multi_pref", new String []{"new_static_multi_pref_value_1","new_static_multi_pref_value_2"}); 58 prefs.setValue("dynamic_single_pref", "new_dynamic_single_pref_value"); 59 prefs.setValues("dynamic_multi_pref", new String []{"new_dynamic_multi_pref_value_1","new_dynamic_multi_pref_value_2"}); 60 61 assertEquals("new_static_single_pref_value", prefs.getValue("static_single_pref", "other")); 63 assertEquals(new String []{"new_static_multi_pref_value_1","new_static_multi_pref_value_2"}, prefs.getValues("static_multi_pref", new String []{"other"})); 64 assertEquals("new_dynamic_single_pref_value", prefs.getValue("dynamic_single_pref", "other")); 65 assertEquals(new String []{"new_dynamic_multi_pref_value_1","new_dynamic_multi_pref_value_2"}, prefs.getValues("dynamic_multi_pref", new String []{"other"})); 66 } 67 }); 68 setRequestLocal(request, result); 69 } 70 if (requestCount == 2) 71 { 72 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("static_single_pref_value", prefs.getValue("static_single_pref", "other")); 82 assertEquals(new String []{"static_multi_pref_value_1","static_multi_pref_value_2"}, prefs.getValues("static_multi_pref", new String []{"other"})); 83 assertEquals("other", prefs.getValue("dynamic_single_pref", "other")); 84 assertEquals(new String []{"other"}, prefs.getValues("dynamic_multi_pref", new String []{"other"})); 85 } 86 }); 87 } 88 } 89 90 public void render(final RenderRequest request, RenderResponse response) throws PortletException, PortletSecurityException, IOException 91 { 92 Result result = null; 93 int invocationCount = getRequestCount(request); 94 if (invocationCount == 0) 95 { 96 PortletURL url = response.createActionURL(); 97 result = new InvokeURLResult(url.toString()); 98 } 99 else if (invocationCount == 1) 100 { 101 PortletURL url = response.createActionURL(); 102 result = new InvokeURLResult(url.toString()); 103 } 104 else if (invocationCount == 2) 105 { 106 result = (Result)getRequestLocal(request); 107 } 108 109 sendResult(response, result); 111 } 112 } 113 | Popular Tags |