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  import javax.xml.bind.JAXBContext;
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    private JAXBContext context;
39  
40    public TestTableSchemaModel() throws Exception {
41      super(TableSchemaModel.class);
42      testColumnSchemaModel = new TestColumnSchemaModel();
43  
44      AS_XML =
45        "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" +
46        "<TableSchema name=\"testTable\" IS_META=\"false\" IS_ROOT=\"false\" READONLY=\"false\">" +
47        "<ColumnSchema name=\"testcolumn\" BLOCKSIZE=\"16384\" BLOOMFILTER=\"NONE\" " +
48        "BLOCKCACHE=\"true\" COMPRESSION=\"GZ\" VERSIONS=\"1\" TTL=\"86400\" IN_MEMORY=\"false\"/>" +
49        "</TableSchema>";
50  
51      AS_PB =
52        "Cgl0ZXN0VGFibGUSEAoHSVNfTUVUQRIFZmFsc2USEAoHSVNfUk9PVBIFZmFsc2USEQoIUkVBRE9O" +
53        "TFkSBWZhbHNlGpcBCgp0ZXN0Y29sdW1uEhIKCUJMT0NLU0laRRIFMTYzODQSEwoLQkxPT01GSUxU" +
54        "RVISBE5PTkUSEgoKQkxPQ0tDQUNIRRIEdHJ1ZRIRCgtDT01QUkVTU0lPThICR1oSDQoIVkVSU0lP" +
55        "TlMSATESDAoDVFRMEgU4NjQwMBISCglJTl9NRU1PUlkSBWZhbHNlGICjBSABKgJHWigA";
56  
57      AS_JSON =
58        "{\"name\":\"testTable\",\"IS_META\":\"false\",\"IS_ROOT\":\"false\"," +
59        "\"READONLY\":\"false\",\"ColumnSchema\":[{\"name\":\"testcolumn\"," +
60        "\"BLOCKSIZE\":\"16384\",\"BLOOMFILTER\":\"NONE\",\"BLOCKCACHE\":\"true\"," +
61        "\"COMPRESSION\":\"GZ\",\"VERSIONS\":\"1\",\"TTL\":\"86400\",\"IN_MEMORY\":\"false\"}]}";
62    }
63  
64    protected TableSchemaModel buildTestModel() {
65      return buildTestModel(TABLE_NAME);
66    }
67  
68    public TableSchemaModel buildTestModel(String name) {
69      TableSchemaModel model = new TableSchemaModel();
70      model.setName(name);
71      model.__setIsMeta(IS_META);
72      model.__setIsRoot(IS_ROOT);
73      model.__setReadOnly(READONLY);
74      model.addColumnFamily(testColumnSchemaModel.buildTestModel());
75      return model;
76    }
77  
78    protected void checkModel(TableSchemaModel model) {
79      checkModel(model, TABLE_NAME);
80    }
81  
82    public void checkModel(TableSchemaModel model, String tableName) {
83      assertEquals(model.getName(), tableName);
84      assertEquals(model.__getIsMeta(), IS_META);
85      assertEquals(model.__getIsRoot(), IS_ROOT);
86      assertEquals(model.__getReadOnly(), READONLY);
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    public void testBuildModel() throws Exception {
95      checkModel(buildTestModel());
96    }
97  
98    public void testFromXML() throws Exception {
99      checkModel(fromXML(AS_XML));
100   }
101 
102   public void testFromPB() throws Exception {
103     checkModel(fromPB(AS_PB));
104   }
105 
106 }
107