1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.apache.hadoop.hbase.rest.model;
22
23 import java.io.StringReader;
24 import java.io.StringWriter;
25
26 import javax.xml.bind.JAXBContext;
27 import javax.xml.bind.JAXBException;
28
29 import junit.framework.TestCase;
30 import org.apache.hadoop.hbase.SmallTests;
31 import org.junit.experimental.categories.Category;
32
33 @Category(SmallTests.class)
34 public class TestColumnSchemaModel extends TestCase {
35
36 protected static final String COLUMN_NAME = "testcolumn";
37 protected static final boolean BLOCKCACHE = true;
38 protected static final int BLOCKSIZE = 16384;
39 protected static final String BLOOMFILTER = "NONE";
40 protected static final String COMPRESSION = "GZ";
41 protected static final boolean IN_MEMORY = false;
42 protected static final int TTL = 86400;
43 protected static final int VERSIONS = 1;
44
45 protected static final String AS_XML =
46 "<ColumnSchema name=\"testcolumn\"" +
47 " BLOCKSIZE=\"16384\"" +
48 " BLOOMFILTER=\"NONE\"" +
49 " BLOCKCACHE=\"true\"" +
50 " COMPRESSION=\"GZ\"" +
51 " VERSIONS=\"1\"" +
52 " TTL=\"86400\"" +
53 " IN_MEMORY=\"false\"/>";
54
55 private JAXBContext context;
56
57 public TestColumnSchemaModel() throws JAXBException {
58 super();
59 context = JAXBContext.newInstance(ColumnSchemaModel.class);
60 }
61
62 protected static ColumnSchemaModel buildTestModel() {
63 ColumnSchemaModel model = new ColumnSchemaModel();
64 model.setName(COLUMN_NAME);
65 model.__setBlockcache(BLOCKCACHE);
66 model.__setBlocksize(BLOCKSIZE);
67 model.__setBloomfilter(BLOOMFILTER);
68 model.__setCompression(COMPRESSION);
69 model.__setInMemory(IN_MEMORY);
70 model.__setTTL(TTL);
71 model.__setVersions(VERSIONS);
72 return model;
73 }
74
75 @SuppressWarnings("unused")
76 private String toXML(ColumnSchemaModel model) throws JAXBException {
77 StringWriter writer = new StringWriter();
78 context.createMarshaller().marshal(model, writer);
79 return writer.toString();
80 }
81
82 private ColumnSchemaModel fromXML(String xml) throws JAXBException {
83 return (ColumnSchemaModel)
84 context.createUnmarshaller().unmarshal(new StringReader(xml));
85 }
86
87 protected static void checkModel(ColumnSchemaModel model) {
88 assertEquals(model.getName(), COLUMN_NAME);
89 assertEquals(model.__getBlockcache(), BLOCKCACHE);
90 assertEquals(model.__getBlocksize(), BLOCKSIZE);
91 assertEquals(model.__getBloomfilter(), BLOOMFILTER);
92 assertTrue(model.__getCompression().equalsIgnoreCase(COMPRESSION));
93 assertEquals(model.__getInMemory(), IN_MEMORY);
94 assertEquals(model.__getTTL(), TTL);
95 assertEquals(model.__getVersions(), VERSIONS);
96 }
97
98 public void testBuildModel() throws Exception {
99 checkModel(buildTestModel());
100 }
101
102 public void testFromXML() throws Exception {
103 checkModel(fromXML(AS_XML));
104 }
105
106 @org.junit.Rule
107 public org.apache.hadoop.hbase.ResourceCheckerJUnitRule cu =
108 new org.apache.hadoop.hbase.ResourceCheckerJUnitRule();
109 }
110