/projects/exoportal-v1.0.2/services/wsrp/impl/src/test/org/exoplatform/services/wsrp/test/TestPortletManagementInterface.java

https://gitlab.com/essere.lab.public/qualitas.class-corpus · Java · 215 lines · 184 code · 21 blank · 10 comment · 8 complexity · 077c232ca5c4d7d65c50fe72242b9c21 MD5 · raw file

  1. /*
  2. * Copyright 2001-2003 The eXo platform SARL All rights reserved.
  3. * Please look at license.txt in info directory for more license detail.
  4. *
  5. * Created on 16 janv. 2004
  6. */
  7. package org.exoplatform.services.wsrp.test;
  8. import org.apache.commons.lang.StringUtils;
  9. import org.exoplatform.services.wsrp.type.*;
  10. import java.rmi.RemoteException;
  11. /**
  12. * @author Mestrallet Benjamin
  13. * benjmestrallet@users.sourceforge.net
  14. */
  15. public class TestPortletManagementInterface extends BaseTest {
  16. public TestPortletManagementInterface(String s) {
  17. super(s);
  18. }
  19. public void testClonePortlet() throws RemoteException {
  20. RegistrationContext rC = registrationOperationsInterface.register(registrationData);
  21. PortletContext pC = fillPortletContext("hello/HelloWorld");
  22. ClonePortletRequest clonePortlet = new ClonePortletRequest();
  23. clonePortlet.setRegistrationContext(rC);
  24. clonePortlet.setPortletContext(pC);
  25. clonePortlet.setUserContext(userContext);
  26. String returnedPH = portletManagementOperationsInterface.clonePortlet(clonePortlet).getPortletHandle();
  27. String[] keys = StringUtils.split(returnedPH, "/");
  28. assertTrue(keys.length == 3);
  29. }
  30. public void testClonePortletWithBadRegistrationHandle() {
  31. RegistrationContext rC = new RegistrationContext();
  32. rC.setRegistrationHandle("dummy_handle");
  33. PortletContext pC = fillPortletContext("hello/HelloWorld");
  34. try {
  35. ClonePortletRequest clonePortlet = new ClonePortletRequest();
  36. clonePortlet.setRegistrationContext(rC);
  37. clonePortlet.setPortletContext(pC);
  38. clonePortlet.setUserContext(userContext);
  39. portletManagementOperationsInterface.clonePortlet(clonePortlet);
  40. fail("The given registration handle was incorrect");
  41. } catch (RemoteException e) {
  42. e.printStackTrace();
  43. }
  44. }
  45. public void testClonePortletWithBadPortletHandle() throws RemoteException {
  46. RegistrationContext rC = registrationOperationsInterface.register(registrationData);
  47. PortletContext pC = fillPortletContext("hello/dummy");
  48. try {
  49. ClonePortletRequest clonePortlet = new ClonePortletRequest();
  50. clonePortlet.setRegistrationContext(rC);
  51. clonePortlet.setPortletContext(pC);
  52. clonePortlet.setUserContext(userContext);
  53. portletManagementOperationsInterface.clonePortlet(clonePortlet);
  54. fail("The given portlet handle was incorrect");
  55. } catch (RemoteException e) {
  56. e.printStackTrace();
  57. }
  58. }
  59. public void testCloneAlreadyClonedPortlet() throws RemoteException {
  60. RegistrationContext rC = registrationOperationsInterface.register(registrationData);
  61. PortletContext pC = fillPortletContext("hello/HelloWorld");
  62. ClonePortletRequest clonePortlet = new ClonePortletRequest();
  63. clonePortlet.setRegistrationContext(rC);
  64. clonePortlet.setPortletContext(pC);
  65. clonePortlet.setUserContext(userContext);
  66. String returnedPH = portletManagementOperationsInterface.clonePortlet(clonePortlet).getPortletHandle();
  67. pC.setPortletHandle(returnedPH);
  68. pC = portletManagementOperationsInterface.clonePortlet(clonePortlet);
  69. assertNotSame(returnedPH, pC.getPortletHandle());
  70. GetPortletPropertiesRequest getPortletProperties = new GetPortletPropertiesRequest();
  71. getPortletProperties.setRegistrationContext(rC);
  72. getPortletProperties.setPortletContext(pC);
  73. getPortletProperties.setUserContext(userContext);
  74. getPortletProperties.setNames(new String[]{"time-format"});
  75. PropertyList list = portletManagementOperationsInterface.
  76. getPortletProperties(getPortletProperties);
  77. Property[] propArray = list.getProperties();
  78. assertEquals(1, propArray.length);
  79. Property property = propArray[0];
  80. assertEquals("HH", property.getStringValue());
  81. }
  82. public void testDestroyPortlet() throws RemoteException {
  83. RegistrationContext rC = registrationOperationsInterface.register(registrationData);
  84. PortletContext pC = fillPortletContext("hello/HelloWorld");
  85. ClonePortletRequest clonePortlet = new ClonePortletRequest();
  86. clonePortlet.setRegistrationContext(rC);
  87. clonePortlet.setPortletContext(pC);
  88. clonePortlet.setUserContext(userContext);
  89. String returnedPH = portletManagementOperationsInterface.clonePortlet(clonePortlet).getPortletHandle();
  90. String[] array = {returnedPH};
  91. DestroyPortletsRequest destroyPortlets = new DestroyPortletsRequest();
  92. destroyPortlets.setRegistrationContext(rC);
  93. destroyPortlets.setPortletHandles(array);
  94. DestroyPortletsResponse response = portletManagementOperationsInterface.destroyPortlets(destroyPortlets);
  95. assertTrue(response.getDestroyFailed() == null || response.getDestroyFailed().length == 0);
  96. }
  97. public void testDestroyNonClonedPortlet() throws RemoteException {
  98. RegistrationContext rC = registrationOperationsInterface.register(registrationData);
  99. String[] array = {"hello/HelloWorld/dummy"};
  100. DestroyPortletsRequest destroyPortlets = new DestroyPortletsRequest();
  101. destroyPortlets.setRegistrationContext(rC);
  102. destroyPortlets.setPortletHandles(array);
  103. DestroyPortletsResponse response = portletManagementOperationsInterface.destroyPortlets(destroyPortlets);
  104. assertEquals("hello/HelloWorld/dummy", response.getDestroyFailed(0).getPortletHandle());
  105. }
  106. public void testGetPortletProperty() throws RemoteException {
  107. RegistrationContext rC = registrationOperationsInterface.register(registrationData);
  108. PortletContext pC = fillPortletContext("hello/HelloWorld");
  109. ClonePortletRequest clonePortlet = new ClonePortletRequest();
  110. clonePortlet.setRegistrationContext(rC);
  111. clonePortlet.setPortletContext(pC);
  112. clonePortlet.setUserContext(userContext);
  113. String returnedPH = portletManagementOperationsInterface.clonePortlet(clonePortlet).getPortletHandle();
  114. pC.setPortletHandle(returnedPH);
  115. GetPortletPropertiesRequest getPortletProperties = new GetPortletPropertiesRequest();
  116. getPortletProperties.setRegistrationContext(rC);
  117. getPortletProperties.setPortletContext(pC);
  118. getPortletProperties.setUserContext(userContext);
  119. PropertyList list = portletManagementOperationsInterface.getPortletProperties(getPortletProperties);
  120. Property[] propArray = list.getProperties();
  121. for (int i = 0; i < propArray.length; i++) {
  122. Property property = propArray[i];
  123. if ("time-format".equals(property.getName())) {
  124. assertEquals("HH", property.getStringValue());
  125. return;
  126. }
  127. }
  128. fail("A property should have been found!!!");
  129. }
  130. public void testWellKnownGetPortletProperty() throws RemoteException {
  131. RegistrationContext rC = registrationOperationsInterface.register(registrationData);
  132. PortletContext pC = fillPortletContext("hello/HelloWorld");
  133. ClonePortletRequest clonePortlet = new ClonePortletRequest();
  134. clonePortlet.setRegistrationContext(rC);
  135. clonePortlet.setPortletContext(pC);
  136. clonePortlet.setUserContext(userContext);
  137. String returnedPH = portletManagementOperationsInterface.clonePortlet(clonePortlet).getPortletHandle();
  138. pC.setPortletHandle(returnedPH);
  139. GetPortletPropertiesRequest getPortletProperties = new GetPortletPropertiesRequest();
  140. getPortletProperties.setRegistrationContext(rC);
  141. getPortletProperties.setPortletContext(pC);
  142. getPortletProperties.setUserContext(userContext);
  143. getPortletProperties.setNames(new String[]{"time-format"});
  144. PropertyList list = portletManagementOperationsInterface.getPortletProperties(getPortletProperties);
  145. Property[] propArray = list.getProperties();
  146. assertEquals(1, propArray.length);
  147. Property property = propArray[0];
  148. assertEquals("HH", property.getStringValue());
  149. }
  150. public void testSetPortletProperty() throws RemoteException {
  151. RegistrationContext rC = registrationOperationsInterface.register(registrationData);
  152. PortletContext pC = fillPortletContext("hello/HelloWorld");
  153. ClonePortletRequest clonePortlet = new ClonePortletRequest();
  154. clonePortlet.setRegistrationContext(rC);
  155. clonePortlet.setPortletContext(pC);
  156. clonePortlet.setUserContext(userContext);
  157. String returnedPH = portletManagementOperationsInterface.clonePortlet(clonePortlet).getPortletHandle();
  158. pC.setPortletHandle(returnedPH);
  159. Property property = new Property();
  160. property.setLang("en");
  161. property.setName("test-prop");
  162. property.setStringValue("test-value");
  163. PropertyList list = new PropertyList();
  164. list.setProperties(new Property[]{property});
  165. SetPortletPropertiesRequest setPortletProperties = new SetPortletPropertiesRequest();
  166. setPortletProperties.setRegistrationContext(rC);
  167. setPortletProperties.setPortletContext(pC);
  168. setPortletProperties.setUserContext(userContext);
  169. setPortletProperties.setPropertyList(list);
  170. PortletContext pCReturned = portletManagementOperationsInterface.setPortletProperties(setPortletProperties);
  171. assertEquals(returnedPH, pCReturned.getPortletHandle());
  172. GetPortletPropertiesRequest getPortletProperties = new GetPortletPropertiesRequest();
  173. getPortletProperties.setRegistrationContext(rC);
  174. getPortletProperties.setPortletContext(pC);
  175. getPortletProperties.setUserContext(userContext);
  176. list = portletManagementOperationsInterface.getPortletProperties(getPortletProperties);
  177. Property[] propArray = list.getProperties();
  178. for (int i = 0; i < propArray.length; i++) {
  179. property = propArray[i];
  180. System.out.println("prop : "+property.getName());
  181. if ("test-prop".equals(property.getName())) {
  182. assertEquals("test-value", property.getStringValue());
  183. return;
  184. }
  185. }
  186. fail("A property should have been found!!!");
  187. }
  188. private PortletContext fillPortletContext(String portletHandle) {
  189. PortletContext portletContext = new PortletContext();
  190. portletContext.setPortletHandle(portletHandle);
  191. portletContext.setPortletState(null);
  192. return portletContext;
  193. }
  194. }