1 11 package org.jboss.portal.test.portlet.preferences.spec; 12 13 import org.jboss.portal.test.portlet.AbstractPortlet; 14 import org.jboss.portal.junit.result.AssertResult; 15 import org.jboss.portal.junit.result.InvokeURLResult; 16 import org.jboss.portal.junit.Result; 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.PortletPreferences; 23 import javax.portlet.RenderRequest; 24 import javax.portlet.RenderResponse; 25 import javax.portlet.PortletURL; 26 import javax.portlet.ReadOnlyException; 27 import java.io.IOException ; 28 29 33 public class ReadOnlyPreferenceCannotBeModifiedPortlet extends AbstractPortlet 34 { 35 public void processAction(final ActionRequest request, ActionResponse response) throws PortletException, PortletSecurityException, IOException 36 { 37 AssertResult result = new AssertResult(); 38 result.execute(new AssertResult.Test() 39 { 40 public void run() throws Exception 41 { 42 PortletPreferences prefs = request.getPreferences(); 44 45 assertEquals("single_pref_value", prefs.getValue("single_pref", "other")); 47 assertEquals(new String []{"multi_pref_value_1","multi_pref_value_2"}, prefs.getValues("multi_pref", new String []{"other"})); 48 49 try 51 { 52 prefs.setValue("single_pref", ""); 53 fail(); 54 } 55 catch (ReadOnlyException e) 56 { 57 } 59 try 60 { 61 prefs.setValues("single_pref", new String []{""}); 62 fail(); 63 } 64 catch (ReadOnlyException e) 65 { 66 } 68 try 69 { 70 prefs.reset("single_pref"); 71 fail(); 72 } 73 catch (ReadOnlyException e) 74 { 75 } 77 try 78 { 79 prefs.setValue("multi_pref", ""); 80 fail(); 81 } 82 catch (ReadOnlyException e) 83 { 84 } 86 try 87 { 88 prefs.setValues("multi_pref", new String []{""}); 89 fail(); 90 } 91 catch (ReadOnlyException e) 92 { 93 } 95 try 96 { 97 prefs.reset("multi_pref"); 98 fail(); 99 } 100 catch (ReadOnlyException e) 101 { 102 } 104 105 assertEquals("single_pref_value", prefs.getValue("single_pref", "other")); 107 assertEquals(new String []{"multi_pref_value_1","multi_pref_value_2"}, prefs.getValues("multi_pref", new String []{"other"})); 108 } 109 }); 110 setRequestLocal(request, result); 111 } 112 113 public void render(final RenderRequest request, RenderResponse response) throws PortletException, PortletSecurityException, IOException 114 { 115 Result result = null; 116 int invocationCount = getRequestCount(request); 117 if (invocationCount == 0) 118 { 119 PortletURL url = response.createActionURL(); 120 result = new InvokeURLResult(url.toString()); 121 } 122 else if (invocationCount == 1) 123 { 124 result = (Result)getRequestLocal(request); 125 } 126 127 sendResult(response, result); 129 } 130 } 131 | Popular Tags |