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 TestPortletManagementInterface extends BaseTest { 19 20 public TestPortletManagementInterface(String s) { 21 super(s); 22 } 23 24 public void testClonePortlet() throws RemoteException { 25 RegistrationContext rC = registrationOperationsInterface.register(registrationData); 26 PortletContext pC = fillPortletContext("hello/HelloWorld"); 27 ClonePortletRequest clonePortlet = new ClonePortletRequest(); 28 clonePortlet.setRegistrationContext(rC); 29 clonePortlet.setPortletContext(pC); 30 clonePortlet.setUserContext(userContext); 31 String returnedPH = portletManagementOperationsInterface.clonePortlet(clonePortlet).getPortletHandle(); 32 String [] keys = StringUtils.split(returnedPH, "/"); 33 assertTrue(keys.length == 3); 34 } 35 36 public void testClonePortletWithBadRegistrationHandle() { 37 RegistrationContext rC = new RegistrationContext(); 38 rC.setRegistrationHandle("dummy_handle"); 39 PortletContext pC = fillPortletContext("hello/HelloWorld"); 40 try { 41 ClonePortletRequest clonePortlet = new ClonePortletRequest(); 42 clonePortlet.setRegistrationContext(rC); 43 clonePortlet.setPortletContext(pC); 44 clonePortlet.setUserContext(userContext); 45 portletManagementOperationsInterface.clonePortlet(clonePortlet); 46 fail("The given registration handle was incorrect"); 47 } catch (RemoteException e) { 48 e.printStackTrace(); 49 } 50 } 51 52 public void testClonePortletWithBadPortletHandle() throws RemoteException { 53 RegistrationContext rC = registrationOperationsInterface.register(registrationData); 54 PortletContext pC = fillPortletContext("hello/dummy"); 55 try { 56 ClonePortletRequest clonePortlet = new ClonePortletRequest(); 57 clonePortlet.setRegistrationContext(rC); 58 clonePortlet.setPortletContext(pC); 59 clonePortlet.setUserContext(userContext); 60 portletManagementOperationsInterface.clonePortlet(clonePortlet); 61 fail("The given portlet handle was incorrect"); 62 } catch (RemoteException e) { 63 e.printStackTrace(); 64 } 65 } 66 67 public void testCloneAlreadyClonedPortlet() throws RemoteException { 68 RegistrationContext rC = registrationOperationsInterface.register(registrationData); 69 PortletContext pC = fillPortletContext("hello/HelloWorld"); 70 ClonePortletRequest clonePortlet = new ClonePortletRequest(); 71 clonePortlet.setRegistrationContext(rC); 72 clonePortlet.setPortletContext(pC); 73 clonePortlet.setUserContext(userContext); 74 String returnedPH = portletManagementOperationsInterface.clonePortlet(clonePortlet).getPortletHandle(); 75 pC.setPortletHandle(returnedPH); 76 pC = portletManagementOperationsInterface.clonePortlet(clonePortlet); 77 assertNotSame(returnedPH, pC.getPortletHandle()); 78 79 GetPortletPropertiesRequest getPortletProperties = new GetPortletPropertiesRequest(); 80 getPortletProperties.setRegistrationContext(rC); 81 getPortletProperties.setPortletContext(pC); 82 getPortletProperties.setUserContext(userContext); 83 getPortletProperties.setNames(new String []{"time-format"}); 84 PropertyList list = portletManagementOperationsInterface. 85 getPortletProperties(getPortletProperties); 86 Property[] propArray = list.getProperties(); 87 assertEquals(1, propArray.length); 88 Property property = propArray[0]; 89 assertEquals("HH", property.getStringValue()); 90 } 91 92 public void testDestroyPortlet() throws RemoteException { 93 RegistrationContext rC = registrationOperationsInterface.register(registrationData); 94 PortletContext pC = fillPortletContext("hello/HelloWorld"); 95 ClonePortletRequest clonePortlet = new ClonePortletRequest(); 96 clonePortlet.setRegistrationContext(rC); 97 clonePortlet.setPortletContext(pC); 98 clonePortlet.setUserContext(userContext); 99 String returnedPH = portletManagementOperationsInterface.clonePortlet(clonePortlet).getPortletHandle(); 100 String [] array = {returnedPH}; 101 DestroyPortletsRequest destroyPortlets = new DestroyPortletsRequest(); 102 destroyPortlets.setRegistrationContext(rC); 103 destroyPortlets.setPortletHandles(array); 104 DestroyPortletsResponse response = portletManagementOperationsInterface.destroyPortlets(destroyPortlets); 105 assertTrue(response.getDestroyFailed() == null || response.getDestroyFailed().length == 0); 106 } 107 108 public void testDestroyNonClonedPortlet() throws RemoteException { 109 RegistrationContext rC = registrationOperationsInterface.register(registrationData); 110 String [] array = {"hello/HelloWorld/dummy"}; 111 DestroyPortletsRequest destroyPortlets = new DestroyPortletsRequest(); 112 destroyPortlets.setRegistrationContext(rC); 113 destroyPortlets.setPortletHandles(array); 114 DestroyPortletsResponse response = portletManagementOperationsInterface.destroyPortlets(destroyPortlets); 115 assertEquals("hello/HelloWorld/dummy", response.getDestroyFailed(0).getPortletHandle()); 116 } 117 118 public void testGetPortletProperty() throws RemoteException { 119 RegistrationContext rC = registrationOperationsInterface.register(registrationData); 120 PortletContext pC = fillPortletContext("hello/HelloWorld"); 121 ClonePortletRequest clonePortlet = new ClonePortletRequest(); 122 clonePortlet.setRegistrationContext(rC); 123 clonePortlet.setPortletContext(pC); 124 clonePortlet.setUserContext(userContext); 125 String returnedPH = portletManagementOperationsInterface.clonePortlet(clonePortlet).getPortletHandle(); 126 pC.setPortletHandle(returnedPH); 127 GetPortletPropertiesRequest getPortletProperties = new GetPortletPropertiesRequest(); 128 getPortletProperties.setRegistrationContext(rC); 129 getPortletProperties.setPortletContext(pC); 130 getPortletProperties.setUserContext(userContext); 131 PropertyList list = portletManagementOperationsInterface.getPortletProperties(getPortletProperties); 132 Property[] propArray = list.getProperties(); 133 for (int i = 0; i < propArray.length; i++) { 134 Property property = propArray[i]; 135 if ("time-format".equals(property.getName())) { 136 assertEquals("HH", property.getStringValue()); 137 return; 138 } 139 } 140 fail("A property should have been found!!!"); 141 } 142 143 public void testWellKnownGetPortletProperty() throws RemoteException { 144 RegistrationContext rC = registrationOperationsInterface.register(registrationData); 145 PortletContext pC = fillPortletContext("hello/HelloWorld"); 146 ClonePortletRequest clonePortlet = new ClonePortletRequest(); 147 clonePortlet.setRegistrationContext(rC); 148 clonePortlet.setPortletContext(pC); 149 clonePortlet.setUserContext(userContext); 150 String returnedPH = portletManagementOperationsInterface.clonePortlet(clonePortlet).getPortletHandle(); 151 pC.setPortletHandle(returnedPH); 152 GetPortletPropertiesRequest getPortletProperties = new GetPortletPropertiesRequest(); 153 getPortletProperties.setRegistrationContext(rC); 154 getPortletProperties.setPortletContext(pC); 155 getPortletProperties.setUserContext(userContext); 156 getPortletProperties.setNames(new String []{"time-format"}); 157 PropertyList list = portletManagementOperationsInterface.getPortletProperties(getPortletProperties); 158 Property[] propArray = list.getProperties(); 159 assertEquals(1, propArray.length); 160 Property property = propArray[0]; 161 assertEquals("HH", property.getStringValue()); 162 } 163 164 public void testSetPortletProperty() throws RemoteException { 165 RegistrationContext rC = registrationOperationsInterface.register(registrationData); 166 PortletContext pC = fillPortletContext("hello/HelloWorld"); 167 ClonePortletRequest clonePortlet = new ClonePortletRequest(); 168 clonePortlet.setRegistrationContext(rC); 169 clonePortlet.setPortletContext(pC); 170 clonePortlet.setUserContext(userContext); 171 String returnedPH = portletManagementOperationsInterface.clonePortlet(clonePortlet).getPortletHandle(); 172 pC.setPortletHandle(returnedPH); 173 174 Property property = new Property(); 175 property.setLang("en"); 176 property.setName("test-prop"); 177 property.setStringValue("test-value"); 178 179 PropertyList list = new PropertyList(); 180 list.setProperties(new Property[]{property}); 181 182 SetPortletPropertiesRequest setPortletProperties = new SetPortletPropertiesRequest(); 183 setPortletProperties.setRegistrationContext(rC); 184 setPortletProperties.setPortletContext(pC); 185 setPortletProperties.setUserContext(userContext); 186 setPortletProperties.setPropertyList(list); 187 PortletContext pCReturned = portletManagementOperationsInterface.setPortletProperties(setPortletProperties); 188 assertEquals(returnedPH, pCReturned.getPortletHandle()); 189 190 GetPortletPropertiesRequest getPortletProperties = new GetPortletPropertiesRequest(); 191 getPortletProperties.setRegistrationContext(rC); 192 getPortletProperties.setPortletContext(pC); 193 getPortletProperties.setUserContext(userContext); 194 list = portletManagementOperationsInterface.getPortletProperties(getPortletProperties); 195 Property[] propArray = list.getProperties(); 196 for (int i = 0; i < propArray.length; i++) { 197 property = propArray[i]; 198 System.out.println("prop : "+property.getName()); 199 if ("test-prop".equals(property.getName())) { 200 assertEquals("test-value", property.getStringValue()); 201 return; 202 } 203 } 204 fail("A property should have been found!!!"); 205 } 206 207 208 private PortletContext fillPortletContext(String portletHandle) { 209 PortletContext portletContext = new PortletContext(); 210 portletContext.setPortletHandle(portletHandle); 211 portletContext.setPortletState(null); 212 return portletContext; 213 } 214 215 } 216 | Popular Tags |