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