PageRenderTime 25ms CodeModel.GetById 41ms RepoModel.GetById 0ms app.codeStats 0ms

/www/api/v1/xmlrpc/tests/unit/src/test/java/org/openx/zone/TestZoneLinkBanner.java

https://github.com/orchestra-io/sample-openx
Java | 245 lines | 109 code | 43 blank | 93 comment | 0 complexity | ad346dcbf55c43e420b19d5afd897dd8 MD5 | raw file
  1. /*
  2. +---------------------------------------------------------------------------+
  3. | OpenX v${RELEASE_MAJOR_MINOR} |
  4. | ======${RELEASE_MAJOR_MINOR_DOUBLE_UNDERLINE} |
  5. | |
  6. | Copyright (c) 2003-2009 OpenX Limited |
  7. | For contact details, see: http://www.openx.org/ |
  8. | |
  9. | This program is free software; you can redistribute it and/or modify |
  10. | it under the terms of the GNU General Public License as published by |
  11. | the Free Software Foundation; either version 2 of the License, or |
  12. | (at your option) any later version. |
  13. | |
  14. | This program is distributed in the hope that it will be useful, |
  15. | but WITHOUT ANY WARRANTY; without even the implied warranty of |
  16. | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
  17. | GNU General Public License for more details. |
  18. | |
  19. | You should have received a copy of the GNU General Public License |
  20. | along with this program; if not, write to the Free Software |
  21. | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
  22. +---------------------------------------------------------------------------+
  23. $Id: TestAddZone.java 20704 2008-05-28 13:28:08Z pawel.dachterski@openx.org $
  24. */
  25. package org.openx.zone;
  26. import java.net.MalformedURLException;
  27. import java.net.URL;
  28. import java.util.Map;
  29. import org.apache.xmlrpc.XmlRpcException;
  30. import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;
  31. import org.openx.config.GlobalSettings;
  32. import org.openx.utils.ErrorMessage;
  33. import org.openx.utils.TextUtils;
  34. /**
  35. * Verify Link Banner method
  36. *
  37. * @author Pawel Dachterski <pawel.dachterski@openx.org>
  38. */
  39. public class TestZoneLinkBanner extends ZoneTestCase {
  40. protected Integer zoneId = null;
  41. protected Integer bannerId = null;
  42. protected void setUp() throws Exception {
  43. super.setUp();
  44. bannerId = createBanner();
  45. zoneId = createZone();
  46. }
  47. protected void tearDown() throws Exception {
  48. deleteBanner(bannerId);
  49. deleteZone(zoneId);
  50. super.tearDown();
  51. }
  52. /**
  53. * Execute test method with error
  54. *
  55. * @param params -
  56. * parameters for test method
  57. * @param errorMsg -
  58. * true error messages
  59. * @throws MalformedURLException
  60. */
  61. private void executeLinkBannerWithError(Object[] params, String errorMsg)
  62. throws MalformedURLException {
  63. try {
  64. execute(ZONE_LINK_BANNER_METHOD, params);
  65. fail(ErrorMessage.METHOD_EXECUTED_SUCCESSFULLY_BUT_SHOULD_NOT_HAVE);
  66. } catch (XmlRpcException e) {
  67. assertEquals(ErrorMessage.WRONG_ERROR_MESSAGE, errorMsg, e
  68. .getMessage());
  69. }
  70. }
  71. /**
  72. * Test method with all required fields and some optional.
  73. *
  74. * @throws XmlRpcException
  75. * @throws MalformedURLException
  76. */
  77. public void testLinkBannerAllReqAndSomeOptionalFields()
  78. throws XmlRpcException, MalformedURLException {
  79. Object[] XMLRPCMethodParameters = new Object[] { sessionId, zoneId, bannerId };
  80. final Boolean result = (Boolean) client
  81. .execute(ZONE_LINK_BANNER_METHOD, XMLRPCMethodParameters);
  82. assertTrue(result);
  83. }
  84. /**
  85. * Test method with all required fields and some optional.
  86. *
  87. * @throws XmlRpcException
  88. * @throws MalformedURLException
  89. */
  90. public void testLinkBannerTxtWithZoneTxt()
  91. throws XmlRpcException, MalformedURLException {
  92. Map<String, Object> zoneParams = getZoneParams("txt");
  93. zoneParams.put(TYPE, 3);
  94. zoneParams.put(PUBLISHER_ID, publisherId);
  95. int zoneId = createZone(zoneParams);
  96. Map<String, Object> bannerParams = getBannerParams("txt");
  97. bannerParams.put(STORAGE_TYPE, STORAGE_TYPES[4]);
  98. bannerParams.put(CAMPAIGN_ID, campaignId);
  99. int bannerId = createBanner(bannerParams);
  100. ((XmlRpcClientConfigImpl) client.getClientConfig())
  101. .setServerURL(new URL(GlobalSettings.getZoneServiceUrl()));
  102. Object[] XMLRPCMethodParameters = new Object[] { sessionId, zoneId, bannerId };
  103. final Boolean result = (Boolean) client
  104. .execute(ZONE_LINK_BANNER_METHOD, XMLRPCMethodParameters);
  105. assertTrue(result);
  106. }
  107. /**
  108. * Test method for case when linking two times Banner with same id.
  109. *
  110. * @throws XmlRpcException
  111. * @throws MalformedURLException
  112. */
  113. public void testLinkBannerOnceAgain()
  114. throws XmlRpcException, MalformedURLException {
  115. Object[] XMLRPCMethodParameters = new Object[] { sessionId, zoneId, bannerId };
  116. client.execute(ZONE_LINK_BANNER_METHOD, XMLRPCMethodParameters);
  117. //TODO: Add expected behavior from https://developer.openx.org/jira/browse/OX-3296
  118. final Boolean result = (Boolean) client
  119. .execute(ZONE_LINK_BANNER_METHOD, XMLRPCMethodParameters);
  120. assertTrue(result);
  121. }
  122. /**
  123. * Test methods for Unknown ID Error, described in API
  124. *
  125. * @throws MalformedURLException
  126. * @throws XmlRpcException
  127. */
  128. public void testLinkBannerUnknownZoneIdError() throws MalformedURLException,
  129. XmlRpcException {
  130. Integer zoneId = createZone();
  131. assertNotNull(zoneId);
  132. deleteZone(zoneId);
  133. Object[] XMLRPCMethodParameters = new Object[] { sessionId, zoneId, bannerId };
  134. executeLinkBannerWithError(XMLRPCMethodParameters, ErrorMessage.getMessage(
  135. ErrorMessage.UNKNOWN_ID_ERROR, ZONE_ID));
  136. }
  137. /**
  138. * Test methods for Unknown ID Error, described in API
  139. *
  140. * @throws MalformedURLException
  141. * @throws XmlRpcException
  142. */
  143. public void testLinkBannerUnknownBannerIdError() throws MalformedURLException,
  144. XmlRpcException {
  145. Integer bannerId = createBanner();
  146. assertNotNull(bannerId);
  147. deleteBanner(bannerId);
  148. Object[] XMLRPCMethodParameters = new Object[] { sessionId, zoneId, bannerId };
  149. executeLinkBannerWithError(XMLRPCMethodParameters, ErrorMessage.getMessage(
  150. ErrorMessage.UNKNOWN_ID_ERROR, BANNER_ID));
  151. }
  152. /**
  153. * Test method with fields that has value of wrong type (error).
  154. *
  155. * @throws MalformedURLException
  156. * @throws XmlRpcException
  157. */
  158. public void testLinkBannerBannerIdWrongTypeError() throws MalformedURLException,
  159. XmlRpcException {
  160. Object[] XMLRPCMethodParameters = new Object[] { sessionId, zoneId, TextUtils.NOT_INTEGER };
  161. executeLinkBannerWithError(XMLRPCMethodParameters, ErrorMessage.getMessage(
  162. ErrorMessage.INCORRECT_PARAMETERS_WANTED_INT_GOT_STRING, "3"));
  163. }
  164. /**
  165. * Test method with fields that has value of wrong type (error).
  166. *
  167. * @throws MalformedURLException
  168. * @throws XmlRpcException
  169. */
  170. public void testLinkBannerZoneIdWrongTypeError() throws MalformedURLException,
  171. XmlRpcException {
  172. Object[] XMLRPCMethodParameters = new Object[] { sessionId, TextUtils.NOT_INTEGER, bannerId };
  173. executeLinkBannerWithError(XMLRPCMethodParameters, ErrorMessage.getMessage(
  174. ErrorMessage.INCORRECT_PARAMETERS_WANTED_INT_GOT_STRING, "2"));
  175. }
  176. /**
  177. * Test method with fields that has value of wrong type (error).
  178. *
  179. * @throws MalformedURLException
  180. * @throws XmlRpcException
  181. */
  182. public void testLinkBannerWrongBannerSizeError() throws MalformedURLException,
  183. XmlRpcException {
  184. Integer zoneId = createZone(getZoneWrongParams("test_"));
  185. Object[] XMLRPCMethodParameters = new Object[] { sessionId, zoneId, bannerId };
  186. executeLinkBannerWithError(XMLRPCMethodParameters, ErrorMessage.getMessage(
  187. ErrorMessage.WORNG_BANNER_SIZE));
  188. }
  189. /**
  190. * Test method with wrong sessionId.
  191. *
  192. * @throws MalformedURLException
  193. * @throws XmlRpcException
  194. */
  195. public void testLinkBannerZoneWrongSessionIdError() throws MalformedURLException,
  196. XmlRpcException {
  197. String sessionId = "phpads11111111111111.11111111";
  198. Object[] XMLRPCMethodParameters = new Object[] { sessionId, zoneId, bannerId };
  199. executeLinkBannerWithError(XMLRPCMethodParameters, ErrorMessage.getMessage(
  200. ErrorMessage.INVALID_SESSION_ID));
  201. }
  202. }