View Javadoc

1   /*
2    *
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *     http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the License for the specific language governing permissions and
17   * limitations under the License.
18   */
19  
20  package org.apache.hadoop.hbase.rest.model;
21  
22  import org.apache.hadoop.hbase.*;
23  import org.apache.hadoop.hbase.testclassification.SmallTests;
24  import org.apache.hadoop.hbase.util.Bytes;
25  
26  import org.junit.experimental.categories.Category;
27  
28  @Category(SmallTests.class)
29  public class TestTableRegionModel extends TestModelBase<TableRegionModel> {
30    private static final String TABLE = "testtable";
31    private static final byte[] START_KEY = Bytes.toBytes("abracadbra");
32    private static final byte[] END_KEY = Bytes.toBytes("zzyzx");
33    private static final long ID = 8731042424L;
34    private static final String LOCATION = "testhost:9876";
35  
36    public TestTableRegionModel() throws Exception {
37      super(TableRegionModel.class);
38  
39      AS_XML =
40        "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><Region endKey=\"enp5eng=\" " +
41            "id=\"8731042424\" location=\"testhost:9876\" " +
42            "name=\"testtable,abracadbra,8731042424.ad9860f031282c46ed431d7af8f94aca.\" " +
43            "startKey=\"YWJyYWNhZGJyYQ==\"/>";
44  
45      AS_JSON =
46        "{\"endKey\":\"enp5eng=\",\"id\":8731042424,\"location\":\"testhost:9876\"," +
47            "\"name\":\"testtable,abracadbra,8731042424.ad9860f031282c46ed431d7af8f94aca.\",\"" +
48            "startKey\":\"YWJyYWNhZGJyYQ==\"}";
49    }
50  
51    protected TableRegionModel buildTestModel() {
52      TableRegionModel model =
53        new TableRegionModel(TABLE, ID, START_KEY, END_KEY, LOCATION);
54      return model;
55    }
56  
57    protected void checkModel(TableRegionModel model) {
58      assertTrue(Bytes.equals(model.getStartKey(), START_KEY));
59      assertTrue(Bytes.equals(model.getEndKey(), END_KEY));
60      assertEquals(model.getId(), ID);
61      assertEquals(model.getLocation(), LOCATION);
62      assertEquals(model.getName(), 
63        TABLE + "," + Bytes.toString(START_KEY) + "," + Long.toString(ID) +
64        ".ad9860f031282c46ed431d7af8f94aca.");
65    }
66  
67    public void testGetName() {
68      TableRegionModel model = buildTestModel();
69      String modelName = model.getName();
70      HRegionInfo hri = new HRegionInfo(TableName.valueOf(TABLE),
71        START_KEY, END_KEY, false, ID);
72      assertEquals(modelName, hri.getRegionNameAsString());
73    }
74  
75    public void testSetName() {
76      TableRegionModel model = buildTestModel();
77      String name = model.getName();
78      model.setName(name);
79      assertEquals(name, model.getName());
80    }
81  
82    @Override
83    public void testFromPB() throws Exception {
84      //no pb ignore
85    }
86  }
87