1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.exoplatform.social.service.rest;
18
19 import org.exoplatform.services.rest.impl.ContainerResponse;
20 import org.exoplatform.services.rest.impl.MultivaluedMapImpl;
21 import org.exoplatform.services.rest.tools.ByteArrayContainerResponseWriter;
22 import org.exoplatform.social.service.test.AbstractResourceTest;
23
24 import javax.ws.rs.core.MultivaluedMap;
25
26
27
28
29
30
31
32 public class LinkShareRestServiceTest extends AbstractResourceTest {
33
34 private final String RIGHT_LINK = "hTTp://google.com";
35 private final String WRONG_LINK = "http://google.com/ahgo/ahgoeh";
36 public void setUp() throws Exception {
37 super.setUp();
38
39 addResource(LinkShareRestService.class, null);
40 }
41
42 public void tearDown() throws Exception {
43 super.tearDown();
44
45 removeResource(LinkShareRestService.class);
46 }
47
48 public void testJsonRightLink() throws Exception {
49 byte[] data = ("{\"link\":\""+ RIGHT_LINK +"\", \"lang\": \"en\"}").getBytes("UTF-8");
50 MultivaluedMap<String, String> h = new MultivaluedMapImpl();
51 h.putSingle("content-type", "application/json");
52 h.putSingle("content-length", "" + data.length);
53 ByteArrayContainerResponseWriter writer = new ByteArrayContainerResponseWriter();
54 ContainerResponse response = service("POST", "/social/linkshare/show.json", "", h, data, writer);
55 assertEquals(200, response.getStatus());
56 assertEquals("application/json;charset=utf-8", response.getContentType().toString());
57 LinkShare linkShare = (LinkShare) response.getEntity();
58 assertEquals(RIGHT_LINK, linkShare.getLink());
59 assertNotNull(linkShare.getTitle());
60 }
61
62 public void testXmlRightLink() throws Exception {
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78 }
79
80 public void testJsonWrongLink() throws Exception {
81 byte[] data = ("{\"link\":\""+ WRONG_LINK +"\", \"lang\": \"en\"}").getBytes("UTF-8");
82 MultivaluedMap<String, String> h = new MultivaluedMapImpl();
83 h.putSingle("content-type", "application/json");
84 h.putSingle("content-length", "" + data.length);
85 ByteArrayContainerResponseWriter writer = new ByteArrayContainerResponseWriter();
86 ContainerResponse response = service("POST", "/social/linkshare/show.json", "", h, data, writer);
87 assertEquals(200, response.getStatus());
88
89 }
90
91 public void testXmlWrongLink() throws Exception {
92
93 }
94
95 public void testBadRequest() throws Exception {
96 ContainerResponse response = service("GET", "/social/linkshare/show.json", "", null, null);
97 assertEquals(405, response.getStatus());
98 response = service("POST", "/social/linkshare/show.json", "", null, null);
99 assertEquals(400, response.getStatus());
100 }
101
102 }