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.util.Arrays;
23  import java.util.List;
24  
25  import org.apache.hadoop.hbase.testclassification.SmallTests;
26  import org.junit.Test;
27  import org.junit.experimental.categories.Category;
28  
29  
30  @Category(SmallTests.class)
31  public class TestNamespacesModel extends TestModelBase<NamespacesModel> {
32  
33    public static final String NAMESPACE_NAME_1 = "testNamespace1";
34    public static final String NAMESPACE_NAME_2 = "testNamespace2";
35  
36    public TestNamespacesModel() throws Exception {
37      super(NamespacesModel.class);
38  
39      AS_XML =
40        "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" +
41        "<Namespaces><Namespace>testNamespace1</Namespace>" +
42        "<Namespace>testNamespace2</Namespace></Namespaces>";
43  
44      AS_PB = "Cg50ZXN0TmFtZXNwYWNlMQoOdGVzdE5hbWVzcGFjZTI=";
45  
46      AS_JSON = "{\"Namespace\":[\"testNamespace1\",\"testNamespace2\"]}";
47    }
48  
49    protected NamespacesModel buildTestModel() {
50      return buildTestModel(NAMESPACE_NAME_1, NAMESPACE_NAME_2);
51    }
52  
53    public NamespacesModel buildTestModel(String... namespaces) {
54      NamespacesModel model = new NamespacesModel();
55      model.setNamespaces(Arrays.asList(namespaces));
56      return model;
57    }
58  
59    protected void checkModel(NamespacesModel model) {
60      checkModel(model, NAMESPACE_NAME_1, NAMESPACE_NAME_2);
61    }
62  
63    public void checkModel(NamespacesModel model, String... namespaceName) {
64      List<String> namespaces = model.getNamespaces();
65      assertEquals(namespaceName.length, namespaces.size());
66      for(int i = 0; i < namespaceName.length; i++){
67        assertTrue(namespaces.contains(namespaceName[i]));
68      }
69    }
70  
71    @Test
72    public void testBuildModel() throws Exception {
73      checkModel(buildTestModel());
74    }
75  
76    @Test
77    public void testFromXML() throws Exception {
78      checkModel(fromXML(AS_XML));
79    }
80  
81    @Test
82    public void testFromPB() throws Exception {
83      checkModel(fromPB(AS_PB));
84    }
85  }