1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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