/core/src/test/java/org/b3log/solo/service/LinkQueryServiceTestCase.java

http://github.com/b3log/b3log-solo · Java · 92 lines · 43 code · 13 blank · 36 comment · 0 complexity · 42f5458325707079344d4b5a9fa33155 MD5 · raw file

  1. /*
  2. * Copyright (c) 2009, 2010, 2011, 2012, B3log Team
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package org.b3log.solo.service;
  17. import org.b3log.latke.model.User;
  18. import org.b3log.latke.util.Requests;
  19. import org.b3log.solo.AbstractTestCase;
  20. import org.b3log.solo.model.Link;
  21. import org.json.JSONObject;
  22. import org.testng.Assert;
  23. import org.testng.annotations.Test;
  24. /**
  25. * {@link LinkQueryService} test case.
  26. *
  27. * @author <a href="mailto:DL88250@gmail.com">Liang Ding</a>
  28. * @version 1.0.0.0, Feb 1, 2012
  29. */
  30. @Test(suiteName = "service")
  31. public class LinkQueryServiceTestCase extends AbstractTestCase {
  32. /**
  33. * Init.
  34. *
  35. * @throws Exception exception
  36. */
  37. @Test
  38. public void init() throws Exception {
  39. final InitService initService = getInitService();
  40. final JSONObject requestJSONObject = new JSONObject();
  41. requestJSONObject.put(User.USER_EMAIL, "test@gmail.com");
  42. requestJSONObject.put(User.USER_NAME, "Admin");
  43. requestJSONObject.put(User.USER_PASSWORD, "pass");
  44. initService.init(requestJSONObject);
  45. final UserQueryService userQueryService = UserQueryService.getInstance();
  46. Assert.assertNotNull(userQueryService.getUserByEmail("test@gmail.com"));
  47. }
  48. /**
  49. * Add Link.
  50. *
  51. * @throws Exception exception
  52. */
  53. @Test(dependsOnMethods = "init")
  54. public void addLink() throws Exception {
  55. final LinkMgmtService linkMgmtService = getLinkMgmtService();
  56. final JSONObject requestJSONObject = new JSONObject();
  57. final JSONObject link = new JSONObject();
  58. requestJSONObject.put(Link.LINK, link);
  59. link.put(Link.LINK_TITLE, "link1 title");
  60. link.put(Link.LINK_ADDRESS, "link1 address");
  61. link.put(Link.LINK_DESCRIPTION, "link1 description");
  62. final String linkId = linkMgmtService.addLink(requestJSONObject);
  63. Assert.assertNotNull(linkId);
  64. }
  65. /**
  66. * Get Links.
  67. *
  68. * @throws Exception exception
  69. */
  70. @Test(dependsOnMethods = "addLink")
  71. public void getLinks() throws Exception {
  72. final LinkQueryService linkQueryService = getLinkQueryService();
  73. final JSONObject paginationRequest =
  74. Requests.buildPaginationRequest("1/10/20");
  75. final JSONObject result = linkQueryService.getLinks(paginationRequest);
  76. Assert.assertNotNull(result);
  77. Assert.assertEquals(result.getJSONArray(Link.LINKS).length(), 1);
  78. }
  79. }