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