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    @Override
50    protected NamespacesModel buildTestModel() {
51      return buildTestModel(NAMESPACE_NAME_1, NAMESPACE_NAME_2);
52    }
53  
54    public NamespacesModel buildTestModel(String... namespaces) {
55      NamespacesModel model = new NamespacesModel();
56      model.setNamespaces(Arrays.asList(namespaces));
57      return model;
58    }
59  
60    @Override
61    protected void checkModel(NamespacesModel model) {
62      checkModel(model, NAMESPACE_NAME_1, NAMESPACE_NAME_2);
63    }
64  
65    public void checkModel(NamespacesModel model, String... namespaceName) {
66      List<String> namespaces = model.getNamespaces();
67      assertEquals(namespaceName.length, namespaces.size());
68      for(int i = 0; i < namespaceName.length; i++){
69        assertTrue(namespaces.contains(namespaceName[i]));
70      }
71    }
72  
73    @Override
74    @Test
75    public void testBuildModel() throws Exception {
76      checkModel(buildTestModel());
77    }
78  
79    @Override
80    @Test
81    public void testFromXML() throws Exception {
82      checkModel(fromXML(AS_XML));
83    }
84  
85    @Override
86    @Test
87    public void testFromPB() throws Exception {
88      checkModel(fromPB(AS_PB));
89    }
90  }