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 TestStorageClusterVersionModel extends TestCase {
34 private static final String VERSION = "0.0.1-testing";
35
36 private static final String AS_XML =
37 "<ClusterVersion>" + VERSION + "</ClusterVersion>";
38
39 private JAXBContext context;
40
41 public TestStorageClusterVersionModel() throws JAXBException {
42 super();
43 context = JAXBContext.newInstance(StorageClusterVersionModel.class);
44 }
45
46 private StorageClusterVersionModel buildTestModel() {
47 StorageClusterVersionModel model = new StorageClusterVersionModel();
48 model.setVersion(VERSION);
49 return model;
50 }
51
52 @SuppressWarnings("unused")
53 private String toXML(StorageClusterVersionModel model) throws JAXBException {
54 StringWriter writer = new StringWriter();
55 context.createMarshaller().marshal(model, writer);
56 return writer.toString();
57 }
58
59 private StorageClusterVersionModel fromXML(String xml) throws JAXBException {
60 return (StorageClusterVersionModel)
61 context.createUnmarshaller().unmarshal(new StringReader(xml));
62 }
63
64 private void checkModel(StorageClusterVersionModel model) {
65 assertEquals(model.getVersion(), VERSION);
66 }
67
68 public void testBuildModel() throws Exception {
69 checkModel(buildTestModel());
70 }
71
72 public void testFromXML() throws Exception {
73 checkModel(fromXML(AS_XML));
74 }
75
76 }
77