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