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.IOException;
23  import java.io.StringReader;
24  import java.io.StringWriter;
25  import java.util.Iterator;
26  
27  import javax.xml.bind.JAXBContext;
28  import javax.xml.bind.JAXBException;
29  
30  import org.apache.hadoop.hbase.SmallTests;
31  import org.apache.hadoop.hbase.util.Base64;
32  
33  import junit.framework.TestCase;
34  import org.junit.experimental.categories.Category;
35  
36  @Category(SmallTests.class)
37  public class TestTableListModel extends TestModelBase<TableListModel> {
38    private static final String TABLE1 = "table1";
39    private static final String TABLE2 = "table2";
40    private static final String TABLE3 = "table3";
41  
42    public TestTableListModel() throws Exception {
43      super(TableListModel.class);
44      AS_XML =
45        "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><TableList><table " +
46            "name=\"table1\"/><table name=\"table2\"/><table name=\"table3\"/></TableList>";
47  
48      AS_PB = "CgZ0YWJsZTEKBnRhYmxlMgoGdGFibGUz";
49  
50      AS_JSON =
51        "{\"table\":[{\"name\":\"table1\"},{\"name\":\"table2\"},{\"name\":\"table3\"}]}";
52    }
53  
54    protected TableListModel buildTestModel() {
55      TableListModel model = new TableListModel();
56      model.add(new TableModel(TABLE1));
57      model.add(new TableModel(TABLE2));
58      model.add(new TableModel(TABLE3));
59      return model;
60    }
61  
62    protected void checkModel(TableListModel model) {
63      Iterator<TableModel> tables = model.getTables().iterator();
64      TableModel table = tables.next();
65      assertEquals(table.getName(), TABLE1);
66      table = tables.next();
67      assertEquals(table.getName(), TABLE2);
68      table = tables.next();
69      assertEquals(table.getName(), TABLE3);
70      assertFalse(tables.hasNext());
71    }
72  }
73