001/**
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018package org.apache.hadoop.hbase.rest.model;
019
020import static org.junit.Assert.assertEquals;
021import static org.junit.Assert.assertTrue;
022
023import java.util.Arrays;
024import java.util.List;
025import org.apache.hadoop.hbase.HBaseClassTestRule;
026import org.apache.hadoop.hbase.testclassification.RestTests;
027import org.apache.hadoop.hbase.testclassification.SmallTests;
028import org.junit.ClassRule;
029import org.junit.Test;
030import org.junit.experimental.categories.Category;
031
032@Category({RestTests.class, SmallTests.class})
033public class TestNamespacesModel extends TestModelBase<NamespacesModel> {
034
035  @ClassRule
036  public static final HBaseClassTestRule CLASS_RULE =
037      HBaseClassTestRule.forClass(TestNamespacesModel.class);
038
039  public static final String NAMESPACE_NAME_1 = "testNamespace1";
040  public static final String NAMESPACE_NAME_2 = "testNamespace2";
041
042  public TestNamespacesModel() throws Exception {
043    super(NamespacesModel.class);
044
045    AS_XML =
046      "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" +
047      "<Namespaces><Namespace>testNamespace1</Namespace>" +
048      "<Namespace>testNamespace2</Namespace></Namespaces>";
049
050    AS_PB = "Cg50ZXN0TmFtZXNwYWNlMQoOdGVzdE5hbWVzcGFjZTI=";
051
052    AS_JSON = "{\"Namespace\":[\"testNamespace1\",\"testNamespace2\"]}";
053  }
054
055  @Override
056  protected NamespacesModel buildTestModel() {
057    return buildTestModel(NAMESPACE_NAME_1, NAMESPACE_NAME_2);
058  }
059
060  public NamespacesModel buildTestModel(String... namespaces) {
061    NamespacesModel model = new NamespacesModel();
062    model.setNamespaces(Arrays.asList(namespaces));
063    return model;
064  }
065
066  @Override
067  protected void checkModel(NamespacesModel model) {
068    checkModel(model, NAMESPACE_NAME_1, NAMESPACE_NAME_2);
069  }
070
071  public void checkModel(NamespacesModel model, String... namespaceName) {
072    List<String> namespaces = model.getNamespaces();
073    assertEquals(namespaceName.length, namespaces.size());
074    for(int i = 0; i < namespaceName.length; i++){
075      assertTrue(namespaces.contains(namespaceName[i]));
076    }
077  }
078
079  @Override
080  @Test
081  public void testBuildModel() throws Exception {
082    checkModel(buildTestModel());
083  }
084
085  @Override
086  @Test
087  public void testFromXML() throws Exception {
088    checkModel(fromXML(AS_XML));
089  }
090
091  @Override
092  @Test
093  public void testFromPB() throws Exception {
094    checkModel(fromPB(AS_PB));
095  }
096}