View Javadoc

1   /*
2    *
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *     http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the License for the specific language governing permissions and
17   * limitations under the License.
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