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