1   /*
2    * Copyright 2010 The Apache Software Foundation
3    *
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *     http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing, software
15   * distributed under the License is distributed on an "AS IS" BASIS,
16   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17   * See the License for the specific language governing permissions and
18   * limitations under the License.
19   */
20  
21  package org.apache.hadoop.hbase.rest.client;
22  
23  import org.apache.hadoop.hbase.*;
24  import org.apache.hadoop.hbase.client.HBaseAdmin;
25  import org.apache.hadoop.hbase.rest.HBaseRESTTestingUtility;
26  import org.apache.hadoop.hbase.rest.client.Client;
27  import org.apache.hadoop.hbase.util.Bytes;
28  
29  import static org.junit.Assert.*;
30  import org.junit.AfterClass;
31  import org.junit.BeforeClass;
32  import org.junit.Test;
33  import org.junit.experimental.categories.Category;
34  
35  @Category(MediumTests.class)
36  public class TestRemoteAdmin {
37    private static final String TABLE_1 = "TestRemoteAdmin_Table_1";
38    private static final byte[] COLUMN_1 = Bytes.toBytes("a");
39    static final HTableDescriptor DESC_1 =  new HTableDescriptor(TABLE_1);
40    private static final HBaseTestingUtility TEST_UTIL =
41      new HBaseTestingUtility();
42    private static final HBaseRESTTestingUtility REST_TEST_UTIL = 
43      new HBaseRESTTestingUtility();
44    private static RemoteAdmin remoteAdmin;
45  
46    @BeforeClass
47    public static void setUpBeforeClass() throws Exception {
48      DESC_1.addFamily(new HColumnDescriptor(COLUMN_1));
49  
50      TEST_UTIL.startMiniCluster();
51      REST_TEST_UTIL.startServletContainer(TEST_UTIL.getConfiguration());
52  
53      remoteAdmin = new RemoteAdmin(new Client(
54        new Cluster().add("localhost", REST_TEST_UTIL.getServletPort())),
55        TEST_UTIL.getConfiguration());
56    }
57  
58    @AfterClass
59    public static void tearDownAfterClass() throws Exception {
60      REST_TEST_UTIL.shutdownServletContainer();
61      TEST_UTIL.shutdownMiniCluster();
62    }
63  
64    @Test
65    public void testCreateAnDeleteTable() throws Exception {
66      assertFalse(remoteAdmin.isTableAvailable(TABLE_1));
67      remoteAdmin.createTable(DESC_1);
68      assertTrue(remoteAdmin.isTableAvailable(TABLE_1));
69      remoteAdmin.deleteTable(TABLE_1);
70      assertFalse(remoteAdmin.isTableAvailable(TABLE_1));
71    }
72  
73    @org.junit.Rule
74    public org.apache.hadoop.hbase.ResourceCheckerJUnitRule cu =
75      new org.apache.hadoop.hbase.ResourceCheckerJUnitRule();
76  }
77