PageRenderTime 44ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/servers/sip-presence/xdm/server/tests/src/test/java/org/openxdm/xcap/client/test/error/NotFoundTest.java

http://mobicents.googlecode.com/
Java | 302 lines | 126 code | 76 blank | 100 comment | 48 complexity | 60bbdd645cd9b12646cd697ebf70b68d MD5 | raw file
Possible License(s): LGPL-3.0, GPL-3.0, LGPL-2.1, GPL-2.0, CC-BY-SA-3.0, CC0-1.0, Apache-2.0, BSD-3-Clause
  1. /*
  2. * JBoss, Home of Professional Open Source
  3. * Copyright 2011, Red Hat, Inc. and individual contributors
  4. * by the @authors tag. See the copyright.txt in the distribution for a
  5. * full listing of individual contributors.
  6. *
  7. * This is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU Lesser General Public License as
  9. * published by the Free Software Foundation; either version 2.1 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This software is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this software; if not, write to the Free
  19. * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  20. * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  21. */
  22. package org.openxdm.xcap.client.test.error;
  23. import static org.junit.Assert.assertTrue;
  24. import java.io.IOException;
  25. import java.util.LinkedList;
  26. import javax.xml.bind.JAXBException;
  27. import junit.framework.JUnit4TestAdapter;
  28. import org.apache.commons.httpclient.HttpException;
  29. import org.junit.Test;
  30. import org.openxdm.xcap.client.Response;
  31. import org.openxdm.xcap.client.test.AbstractXDMJunitOldClientTest;
  32. import org.openxdm.xcap.common.error.NotFoundException;
  33. import org.openxdm.xcap.common.key.UserAttributeUriKey;
  34. import org.openxdm.xcap.common.key.UserDocumentUriKey;
  35. import org.openxdm.xcap.common.key.UserElementUriKey;
  36. import org.openxdm.xcap.common.resource.ElementResource;
  37. import org.openxdm.xcap.common.uri.AttributeSelector;
  38. import org.openxdm.xcap.common.uri.ElementSelector;
  39. import org.openxdm.xcap.common.uri.ElementSelectorStep;
  40. import org.openxdm.xcap.common.uri.ElementSelectorStepByPos;
  41. public class NotFoundTest extends AbstractXDMJunitOldClientTest {
  42. public static junit.framework.Test suite() {
  43. return new JUnit4TestAdapter(NotFoundTest.class);
  44. }
  45. @Test
  46. public void test() throws HttpException, IOException, JAXBException, InterruptedException {
  47. // exception for response codes
  48. NotFoundException exception = new NotFoundException();
  49. // create content for tests
  50. String documentContent =
  51. "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
  52. "<resource-lists xmlns=\"urn:ietf:params:xml:ns:resource-lists\">" +
  53. "<list/>" +
  54. "</resource-lists>";
  55. String elementContent = "<list xmlns=\"urn:ietf:params:xml:ns:resource-lists\"/>";
  56. // create uri keys
  57. UserDocumentUriKey documentKey = new UserDocumentUriKey(appUsage.getAUID(),user,documentName);
  58. UserDocumentUriKey fakeAppUsageDocumentKey = new UserDocumentUriKey("eduardomartinsappusage",user,documentName);
  59. LinkedList<ElementSelectorStep> elementSelectorSteps = new LinkedList<ElementSelectorStep>();
  60. ElementSelectorStep step1 = new ElementSelectorStep("resource-lists");
  61. ElementSelectorStep step2 = new ElementSelectorStepByPos("list",2);
  62. elementSelectorSteps.add(step1);
  63. elementSelectorSteps.addLast(step2);
  64. ElementSelector elementSelector = new ElementSelector(elementSelectorSteps);
  65. UserElementUriKey elementParentKey = new UserElementUriKey(appUsage.getAUID(),user,documentName,elementSelector,null);
  66. UserAttributeUriKey attrWithElementKey = new UserAttributeUriKey(appUsage.getAUID(),user,documentName,elementSelector,new AttributeSelector("name"),null);
  67. UserAttributeUriKey fakeAppUsageAttrWithElementKey = new UserAttributeUriKey("eduardomartinsappusage",user,documentName,elementSelector,new AttributeSelector("name"),null);
  68. ElementSelectorStep step3 = new ElementSelectorStep("display-name");
  69. elementSelectorSteps.addLast(step3);
  70. elementSelector = new ElementSelector(elementSelectorSteps);
  71. UserElementUriKey elementKey = new UserElementUriKey(appUsage.getAUID(),user,documentName,elementSelector,null);
  72. UserElementUriKey fakeAppUsageElementKey = new UserElementUriKey("eduardomartinsappusage",user,documentName,elementSelector,null);
  73. UserAttributeUriKey attrWithoutElementKey = new UserAttributeUriKey(appUsage.getAUID(),user,documentName,elementSelector,new AttributeSelector("name"),null);
  74. // DOCUMENT PARENT NOT FOUND
  75. client.put(documentKey, appUsage.getMimetype(),documentContent,null);
  76. client.delete(documentKey,null);
  77. // 1. get document and document parent not found
  78. // send get request and get response
  79. Response response = client.get(fakeAppUsageDocumentKey,null);
  80. // check get response
  81. assertTrue("Get response must exists",response != null);
  82. assertTrue("Get response code should be "+exception.getResponseStatus(),response.getCode() == exception.getResponseStatus());
  83. // 2. delete document and document parent not found
  84. // send delete request and get response
  85. response = client.delete(fakeAppUsageDocumentKey,null);
  86. // check delete response
  87. assertTrue("Delete response must exists",response != null);
  88. assertTrue("Delete response code should be "+exception.getResponseStatus(),response.getCode() == exception.getResponseStatus());
  89. // 3. get element and document parent not found
  90. // send get request and get response
  91. response = client.get(fakeAppUsageElementKey,null);
  92. // check get response
  93. assertTrue("Get response must exists",response != null);
  94. assertTrue("Get response code should be "+exception.getResponseStatus(),response.getCode() == exception.getResponseStatus());
  95. // 4. delete element and document parent not found
  96. // send delete request and get response
  97. response = client.delete(fakeAppUsageElementKey,null);
  98. // check delete response
  99. assertTrue("Delete response must exists",response != null);
  100. assertTrue("Delete response code should be "+exception.getResponseStatus(),response.getCode() == exception.getResponseStatus());
  101. // 5. get attribute and document parent not found
  102. // send get request and get response
  103. response = client.get(fakeAppUsageAttrWithElementKey,null);
  104. // check get response
  105. assertTrue("Get response must exists",response != null);
  106. assertTrue("Get response code should be "+exception.getResponseStatus(),response.getCode() == exception.getResponseStatus());
  107. // 6. delete attribute and document parent not found
  108. // send delete request and get response
  109. response = client.delete(fakeAppUsageAttrWithElementKey,null);
  110. // check delete response
  111. assertTrue("Delete response must exists",response != null);
  112. assertTrue("Delete response code should be "+exception.getResponseStatus(),response.getCode() == exception.getResponseStatus());
  113. // DOCUMENT NOT FOUND
  114. // 7. get document and document not found
  115. // send get request and get response
  116. response = client.get(documentKey,null);
  117. // check get response
  118. assertTrue("Get response must exists",response != null);
  119. assertTrue("Get response code should be "+exception.getResponseStatus(),response.getCode() == exception.getResponseStatus());
  120. // 8. delete document and document not found
  121. // send delete request and get response
  122. response = client.delete(documentKey,null);
  123. // check delete response
  124. assertTrue("Delete response must exists",response != null);
  125. assertTrue("Delete response code should be "+exception.getResponseStatus(),response.getCode() == exception.getResponseStatus());
  126. // 9. get element and document not found
  127. // send get request and get response
  128. response = client.get(elementKey,null);
  129. // check get response
  130. assertTrue("Get response must exists",response != null);
  131. assertTrue("Get response code should be "+exception.getResponseStatus(),response.getCode() == exception.getResponseStatus());
  132. // 10. delete element and document not found
  133. // send delete request and get response
  134. response = client.delete(elementKey,null);
  135. // check delete response
  136. assertTrue("Delete response must exists",response != null);
  137. assertTrue("Delete response code should be "+exception.getResponseStatus(),response.getCode() == exception.getResponseStatus());
  138. // 11. get attribute and document not found
  139. // send get request and get response
  140. response = client.get(attrWithElementKey,null);
  141. // check get response
  142. assertTrue("Get response must exists",response != null);
  143. assertTrue("Get response code should be "+exception.getResponseStatus(),response.getCode() == exception.getResponseStatus());
  144. // 12. delete attribute and document not found
  145. // send delete request and get response
  146. response = client.delete(attrWithElementKey,null);
  147. // check delete response
  148. assertTrue("Delete response must exists",response != null);
  149. assertTrue("Delete response code should be "+exception.getResponseStatus(),response.getCode() == exception.getResponseStatus());
  150. // ELEMENT PARENT NOT FOUND
  151. // send put request and get response
  152. response = client.put(documentKey,appUsage.getMimetype(),documentContent,null);
  153. // check put response
  154. assertTrue("Put response must exists",response != null);
  155. assertTrue("Put response code should be 201",response.getCode() == 201);
  156. // 13. get element and element parent not found
  157. // send get request and get response
  158. response = client.get(elementParentKey,null);
  159. // check get response
  160. assertTrue("Get response must exists",response != null);
  161. assertTrue("Get response code should be "+exception.getResponseStatus(),response.getCode() == exception.getResponseStatus());
  162. // 14. get attribute and element parent not found
  163. // send get request and get response
  164. response = client.get(attrWithoutElementKey,null);
  165. // check get response
  166. assertTrue("Get response must exists",response != null);
  167. assertTrue("Get response code should be "+exception.getResponseStatus(),response.getCode() == exception.getResponseStatus());
  168. // 15. delete element and element parent not found
  169. // send delete request and get response
  170. response = client.delete(elementParentKey,null);
  171. // check delete response
  172. assertTrue("Delete response must exists",response != null);
  173. assertTrue("Delete response code should be "+exception.getResponseStatus(),response.getCode() == exception.getResponseStatus());
  174. // 16. delete attribute and element parent not found
  175. // send delete request and get response
  176. response = client.delete(attrWithoutElementKey,null);
  177. // check delete response
  178. assertTrue("Delete response must exists",response != null);
  179. assertTrue("Delete response code should be "+exception.getResponseStatus(),response.getCode() == exception.getResponseStatus());
  180. // ELEMENT NOT FOUND
  181. // send put request and get response
  182. response = client.put(elementParentKey,ElementResource.MIMETYPE,elementContent,null);
  183. // check put response
  184. assertTrue("Put response must exists",response != null);
  185. assertTrue("Put response code should be 201",response.getCode() == 201);
  186. // 17. get element and element not found
  187. // send get request and get response
  188. response = client.get(elementKey,null);
  189. // check get response
  190. assertTrue("Get response must exists",response != null);
  191. assertTrue("Get response code should be "+exception.getResponseStatus(),response.getCode() == exception.getResponseStatus());
  192. // 18. delete element and element not found
  193. // send delete request and get response
  194. response = client.delete(elementKey,null);
  195. // check delete response
  196. assertTrue("Delete response must exists",response != null);
  197. assertTrue("Delete response code should be "+exception.getResponseStatus(),response.getCode() == exception.getResponseStatus());
  198. // 19. get attribute and element not found
  199. // send get request and get response
  200. response = client.get(attrWithoutElementKey,null);
  201. // check get response
  202. assertTrue("Get response must exists",response != null);
  203. assertTrue("Get response code should be "+exception.getResponseStatus(),response.getCode() == exception.getResponseStatus());
  204. // 20. delete attribute and element not found
  205. // send delete request and get response
  206. response = client.delete(attrWithoutElementKey,null);
  207. // check delete response
  208. assertTrue("Delete response must exists",response != null);
  209. assertTrue("Delete response code should be "+exception.getResponseStatus(),response.getCode() == exception.getResponseStatus());
  210. // ATTRIBUTE NOT FOUND
  211. // 21. get attribute and attribute not found
  212. // send get request and get response
  213. response = client.get(attrWithElementKey,null);
  214. // check get response
  215. assertTrue("Get response must exists",response != null);
  216. assertTrue("Get response code should be "+exception.getResponseStatus(),response.getCode() == exception.getResponseStatus());
  217. // 22. delete attribute and attribute not found
  218. // send delete request and get response
  219. response = client.delete(attrWithElementKey,null);
  220. // check delete response
  221. assertTrue("Delete response must exists",response != null);
  222. assertTrue("Delete response code should be "+exception.getResponseStatus(),response.getCode() == exception.getResponseStatus());
  223. // clean up
  224. client.delete(documentKey,null);
  225. }
  226. }