/core/src/test/java/org/b3log/solo/service/LinkQueryServiceTestCase.java
Java | 92 lines | 43 code | 13 blank | 36 comment | 0 complexity | 42f5458325707079344d4b5a9fa33155 MD5 | raw file
Possible License(s): Apache-2.0, LGPL-2.1
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 */ 16package org.b3log.solo.service; 17 18import org.b3log.latke.model.User; 19import org.b3log.latke.util.Requests; 20import org.b3log.solo.AbstractTestCase; 21import org.b3log.solo.model.Link; 22import org.json.JSONObject; 23import org.testng.Assert; 24import org.testng.annotations.Test; 25 26/** 27 * {@link LinkQueryService} test case. 28 * 29 * @author <a href="mailto:DL88250@gmail.com">Liang Ding</a> 30 * @version 1.0.0.0, Feb 1, 2012 31 */ 32@Test(suiteName = "service") 33public class LinkQueryServiceTestCase extends AbstractTestCase { 34 35 /** 36 * Init. 37 * 38 * @throws Exception exception 39 */ 40 @Test 41 public void init() throws Exception { 42 final InitService initService = getInitService(); 43 44 final JSONObject requestJSONObject = new JSONObject(); 45 requestJSONObject.put(User.USER_EMAIL, "test@gmail.com"); 46 requestJSONObject.put(User.USER_NAME, "Admin"); 47 requestJSONObject.put(User.USER_PASSWORD, "pass"); 48 49 initService.init(requestJSONObject); 50 51 final UserQueryService userQueryService = UserQueryService.getInstance(); 52 Assert.assertNotNull(userQueryService.getUserByEmail("test@gmail.com")); 53 } 54 55 /** 56 * Add Link. 57 * 58 * @throws Exception exception 59 */ 60 @Test(dependsOnMethods = "init") 61 public void addLink() throws Exception { 62 final LinkMgmtService linkMgmtService = getLinkMgmtService(); 63 64 final JSONObject requestJSONObject = new JSONObject(); 65 final JSONObject link = new JSONObject(); 66 requestJSONObject.put(Link.LINK, link); 67 68 link.put(Link.LINK_TITLE, "link1 title"); 69 link.put(Link.LINK_ADDRESS, "link1 address"); 70 link.put(Link.LINK_DESCRIPTION, "link1 description"); 71 72 final String linkId = linkMgmtService.addLink(requestJSONObject); 73 Assert.assertNotNull(linkId); 74 } 75 76 /** 77 * Get Links. 78 * 79 * @throws Exception exception 80 */ 81 @Test(dependsOnMethods = "addLink") 82 public void getLinks() throws Exception { 83 final LinkQueryService linkQueryService = getLinkQueryService(); 84 85 final JSONObject paginationRequest = 86 Requests.buildPaginationRequest("1/10/20"); 87 final JSONObject result = linkQueryService.getLinks(paginationRequest); 88 89 Assert.assertNotNull(result); 90 Assert.assertEquals(result.getJSONArray(Link.LINKS).length(), 1); 91 } 92}