View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
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  }