1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.hadoop.chukwa.rest.resource;
19
20 import javax.ws.rs.core.MultivaluedMap;
21
22 import org.apache.hadoop.chukwa.hicc.HiccWebServer;
23 import org.apache.hadoop.chukwa.rest.bean.ColumnBean;
24 import org.apache.hadoop.chukwa.rest.bean.PagesBean;
25 import org.apache.hadoop.chukwa.rest.bean.ReturnCodeBean;
26 import org.apache.hadoop.chukwa.rest.bean.ViewBean;
27 import org.apache.hadoop.chukwa.rest.bean.WidgetBean;
28
29 import com.sun.jersey.api.client.Client;
30 import com.sun.jersey.core.util.MultivaluedMapImpl;
31
32 public class TestViewResource extends SetupTestEnv{
33 public void testViewClone() {
34 MultivaluedMap form = new MultivaluedMapImpl();
35 form.add("owner", "system");
36 form.add("view_name","test");
37 form.add("view_vid","default");
38 client = Client.create();
39 resource = client.resource("http://localhost:"+restPort);
40 ReturnCodeBean result = resource.path("/hicc/v1/view").
41 header("Authorization", authorization).
42 post(ReturnCodeBean.class,form);
43 assertEquals(1,result.getCode());
44 }
45
46 public void testViewSave() {
47 client = Client.create();
48 resource = client.resource("http://localhost:"+restPort);
49 ViewBean view = resource.path("/hicc/v1/view/vid/test").header("Authorization", authorization).get(ViewBean.class);
50 view.setPermissionType("private");
51 client = Client.create();
52 resource = client.resource("http://localhost:"+restPort);
53 ReturnCodeBean result = (ReturnCodeBean) resource.path("/hicc/v1/view").
54 header("Content-Type","application/json").
55 header("Authorization", authorization).
56 put(ReturnCodeBean.class, view);
57 assertEquals(1, result.getCode());
58 }
59
60 public void testViewLoad() {
61 client = Client.create();
62 resource = client.resource("http://localhost:"+restPort);
63 ViewBean view = resource.path("/hicc/v1/view/vid/test").header("Authorization", authorization).get(ViewBean.class);
64 assertEquals("test", view.getName());
65 assertEquals("admin", view.getOwner());
66 assertEquals("private", view.getPermissionType());
67 }
68
69 public void testViewDelete() {
70 client = Client.create();
71 resource = client.resource("http://localhost:"+restPort);
72 ReturnCodeBean result = resource.path("/hicc/v1/view/delete/admin/vid/test").
73 header("Authorization", authorization).
74 delete(ReturnCodeBean.class);
75 assertEquals(1,result.getCode());
76 }
77 }