1 7 package org.exoplatform.services.wsrp.test; 8 9 import org.apache.commons.lang.StringUtils; 10 import org.exoplatform.services.wsrp.type.*; 11 12 import java.rmi.RemoteException ; 13 14 18 public class TestGetMarkup extends BaseTest{ 19 20 public TestGetMarkup(String s) { 21 super(s); 22 } 23 24 public void setUp() throws Exception { 25 super.setUp(); 26 } 27 28 public void testGetMarkupForSeveralModes() throws Exception { 29 ServiceDescription sd = getServiceDescription(new String []{"en"}); 30 RegistrationContext rc = null; 31 if(sd.isRequiresRegistration()) 32 rc = new RegistrationContext(); 33 String portletHandle = "hello/HelloWorld2"; 34 PortletContext portletContext = new PortletContext(); 35 portletContext.setPortletHandle(portletHandle); 36 portletContext.setPortletState(null); 37 MarkupRequest getMarkup = getMarkup(rc, portletContext); 38 MarkupResponse response = markupOperationsInterface.getMarkup(getMarkup); 39 assertEquals("HelloWorld title", response.getMarkupContext().getPreferredTitle()); 40 assertEquals("Everything is ok", response.getMarkupContext().getMarkupString()); 41 markupParams.setMode("wsrp:help"); 42 runtimeContext.setSessionID(response.getSessionContext().getSessionID()); 43 manageTemplatesOptimization(sd, portletHandle); 44 manageUserContextOptimization(sd, portletHandle, getMarkup); 45 response = markupOperationsInterface.getMarkup(getMarkup); 46 assertEquals("HelloWorld title", response.getMarkupContext().getPreferredTitle()); 47 assertEquals("Everything is ok in Help mode", response.getMarkupContext().getMarkupString()); 48 } 49 50 public void testGetMarkupForSeveralWindowStates() throws Exception { 51 ServiceDescription sd = getServiceDescription(new String []{"en"}); 52 RegistrationContext rc = null; 53 if(sd.isRequiresRegistration()) 54 rc = new RegistrationContext(); 55 String portletHandle = "hello/HelloWorld2"; 56 PortletContext portletContext = new PortletContext(); 57 portletContext.setPortletHandle(portletHandle); 58 portletContext.setPortletState(null); 59 MarkupRequest getMarkup = getMarkup(rc, portletContext); 60 MarkupResponse response = markupOperationsInterface.getMarkup(getMarkup); 61 assertEquals("HelloWorld title", response.getMarkupContext().getPreferredTitle()); 62 assertEquals("Everything is ok", response.getMarkupContext().getMarkupString()); 63 markupParams.setWindowState("wsrp:maximized"); 64 runtimeContext.setSessionID(response.getSessionContext().getSessionID()); 65 manageTemplatesOptimization(sd, portletHandle); 66 manageUserContextOptimization(sd, portletHandle, getMarkup); 67 response = markupOperationsInterface.getMarkup(getMarkup); 68 assertEquals("HelloWorld title", response.getMarkupContext().getPreferredTitle()); 69 assertEquals("Everything is ok in Maximized state", response.getMarkupContext().getMarkupString()); 70 } 71 72 public void testGetMarkupWithRewrittenURLInIt() throws RemoteException { 73 ServiceDescription sd = getServiceDescription(new String []{"en"}); 74 RegistrationContext rc = null; 75 if(sd.isRequiresRegistration()) 76 rc = new RegistrationContext(); 77 String portletHandle = "hello/PortletToTestMarkupWithRewrittenURL"; 78 PortletContext portletContext = new PortletContext(); 79 portletContext.setPortletHandle(portletHandle); 80 portletContext.setPortletState(null); 81 MarkupRequest getMarkup = getMarkup(rc, portletContext); 82 MarkupResponse response = markupOperationsInterface.getMarkup(getMarkup); 83 String s = response.getMarkupContext().getMarkupString(); 84 int index = s.indexOf("&ns="); 85 s = s.substring(index + "&ns=".length()); 86 index = s.indexOf("&is="); 87 s = StringUtils.left(s, index); 88 markupParams.setMode("wsrp:view"); 89 markupParams.setWindowState("wsrp:maximized"); 90 markupParams.setNavigationalState(s); 91 runtimeContext.setSessionID(response.getSessionContext().getSessionID()); 92 manageTemplatesOptimization(sd, portletHandle); 93 manageUserContextOptimization(sd, portletHandle, getMarkup); 94 response = markupOperationsInterface.getMarkup(getMarkup); 95 assertEquals("value", response.getMarkupContext().getMarkupString()); 96 } 97 98 public void testGetMarkupOfAClonedPortlet() throws Exception { 99 System.out.println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); 100 RegistrationContext rC = registrationOperationsInterface.register(registrationData); 101 resolveRegistrationContext(rC); 102 PortletContext portletContext = new PortletContext(); 103 portletContext.setPortletHandle("hello/HelloWorld2"); 104 ClonePortletRequest clonePortlet = new ClonePortletRequest(); 105 clonePortlet.setRegistrationContext(rC); 106 clonePortlet.setPortletContext(portletContext); 107 clonePortlet.setUserContext(userContext); 108 PortletContext returnedPC = portletManagementOperationsInterface.clonePortlet(clonePortlet); 109 System.out.println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); 110 Property property = new Property(); 112 property.setLang("en"); 113 property.setName("test-prop"); 114 property.setStringValue("test-value"); 115 PropertyList list = new PropertyList(); 116 list.setProperties(new Property[]{property}); 117 SetPortletPropertiesRequest setPortletProperties = new SetPortletPropertiesRequest(); 118 setPortletProperties.setRegistrationContext(rC); 119 setPortletProperties.setPortletContext(returnedPC); 120 setPortletProperties.setUserContext(userContext); 121 setPortletProperties.setPropertyList(list); 122 returnedPC = portletManagementOperationsInterface.setPortletProperties(setPortletProperties); 123 System.out.println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); 124 MarkupRequest getMarkup = getMarkup(rC, returnedPC); 125 MarkupResponse response = markupOperationsInterface.getMarkup(getMarkup); 126 assertEquals("Everything is more than ok", response.getMarkupContext().getMarkupString()); 127 } 128 129 } 130 | Popular Tags |