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 java.util.Iterator;
23  
24  import org.apache.hadoop.hbase.testclassification.SmallTests;
25  
26  import org.junit.experimental.categories.Category;
27  
28  @Category(SmallTests.class)
29  public class TestTableSchemaModel extends TestModelBase<TableSchemaModel> {
30  
31    public static final String TABLE_NAME = "testTable";
32    private static final boolean IS_META = false;
33    private static final boolean IS_ROOT = false;
34    private static final boolean READONLY = false;
35  
36    TestColumnSchemaModel testColumnSchemaModel;
37  
38    public TestTableSchemaModel() throws Exception {
39      super(TableSchemaModel.class);
40      testColumnSchemaModel = new TestColumnSchemaModel();
41  
42      AS_XML =
43        "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" +
44        "<TableSchema name=\"testTable\" IS_META=\"false\" IS_ROOT=\"false\" READONLY=\"false\">" +
45        "<ColumnSchema name=\"testcolumn\" BLOCKSIZE=\"16384\" BLOOMFILTER=\"NONE\" " +
46        "BLOCKCACHE=\"true\" COMPRESSION=\"GZ\" VERSIONS=\"1\" TTL=\"86400\" IN_MEMORY=\"false\"/>" +
47        "</TableSchema>";
48  
49      AS_PB =
50        "Cgl0ZXN0VGFibGUSEAoHSVNfTUVUQRIFZmFsc2USEAoHSVNfUk9PVBIFZmFsc2USEQoIUkVBRE9O" +
51        "TFkSBWZhbHNlGpcBCgp0ZXN0Y29sdW1uEhIKCUJMT0NLU0laRRIFMTYzODQSEwoLQkxPT01GSUxU" +
52        "RVISBE5PTkUSEgoKQkxPQ0tDQUNIRRIEdHJ1ZRIRCgtDT01QUkVTU0lPThICR1oSDQoIVkVSU0lP" +
53        "TlMSATESDAoDVFRMEgU4NjQwMBISCglJTl9NRU1PUlkSBWZhbHNlGICjBSABKgJHWigA";
54  
55      AS_JSON =
56        "{\"name\":\"testTable\",\"IS_META\":\"false\",\"IS_ROOT\":\"false\"," +
57        "\"READONLY\":\"false\",\"ColumnSchema\":[{\"name\":\"testcolumn\"," +
58        "\"BLOCKSIZE\":\"16384\",\"BLOOMFILTER\":\"NONE\",\"BLOCKCACHE\":\"true\"," +
59        "\"COMPRESSION\":\"GZ\",\"VERSIONS\":\"1\",\"TTL\":\"86400\",\"IN_MEMORY\":\"false\"}]}";
60    }
61  
62    @Override
63    protected TableSchemaModel buildTestModel() {
64      return buildTestModel(TABLE_NAME);
65    }
66  
67    public TableSchemaModel buildTestModel(String name) {
68      TableSchemaModel model = new TableSchemaModel();
69      model.setName(name);
70      model.__setIsMeta(IS_META);
71      model.__setIsRoot(IS_ROOT);
72      model.__setReadOnly(READONLY);
73      model.addColumnFamily(testColumnSchemaModel.buildTestModel());
74      return model;
75    }
76  
77    @Override
78    protected void checkModel(TableSchemaModel model) {
79      checkModel(model, TABLE_NAME);
80    }
81  
82    public void checkModel(TableSchemaModel model, String tableName) {
83      assertEquals(tableName, model.getName());
84      assertEquals(IS_META, model.__getIsMeta());
85      assertEquals(IS_ROOT, model.__getIsRoot());
86      assertEquals(READONLY, model.__getReadOnly());
87      Iterator<ColumnSchemaModel> families = model.getColumns().iterator();
88      assertTrue(families.hasNext());
89      ColumnSchemaModel family = families.next();
90      testColumnSchemaModel.checkModel(family);
91      assertFalse(families.hasNext());
92    }
93  
94    @Override
95    public void testBuildModel() throws Exception {
96      checkModel(buildTestModel());
97    }
98  
99    @Override
100   public void testFromXML() throws Exception {
101     checkModel(fromXML(AS_XML));
102   }
103 
104   @Override
105   public void testFromPB() throws Exception {
106     checkModel(fromPB(AS_PB));
107   }
108 
109 }