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.jupiter.api.Assertions.assertEquals;
021import static org.junit.jupiter.api.Assertions.assertTrue;
022
023import java.util.Arrays;
024import java.util.List;
025import org.apache.hadoop.hbase.testclassification.RestTests;
026import org.apache.hadoop.hbase.testclassification.SmallTests;
027import org.junit.jupiter.api.Tag;
028import org.junit.jupiter.api.Test;
029
030@Tag(RestTests.TAG)
031@Tag(SmallTests.TAG)
032public class TestNamespacesModel extends TestModelBase<NamespacesModel> {
033
034  public static final String NAMESPACE_NAME_1 = "testNamespace1";
035  public static final String NAMESPACE_NAME_2 = "testNamespace2";
036
037  public TestNamespacesModel() throws Exception {
038    super(NamespacesModel.class);
039
040    AS_XML = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>"
041      + "<Namespaces><Namespace>testNamespace1</Namespace>"
042      + "<Namespace>testNamespace2</Namespace></Namespaces>";
043
044    AS_PB = "Cg50ZXN0TmFtZXNwYWNlMQoOdGVzdE5hbWVzcGFjZTI=";
045
046    AS_JSON = "{\"Namespace\":[\"testNamespace1\",\"testNamespace2\"]}";
047  }
048
049  @Override
050  protected NamespacesModel buildTestModel() {
051    return buildTestModel(NAMESPACE_NAME_1, NAMESPACE_NAME_2);
052  }
053
054  public NamespacesModel buildTestModel(String... namespaces) {
055    NamespacesModel model = new NamespacesModel();
056    model.setNamespaces(Arrays.asList(namespaces));
057    return model;
058  }
059
060  @Override
061  protected void checkModel(NamespacesModel model) {
062    checkModel(model, NAMESPACE_NAME_1, NAMESPACE_NAME_2);
063  }
064
065  public void checkModel(NamespacesModel model, String... namespaceName) {
066    List<String> namespaces = model.getNamespaces();
067    assertEquals(namespaceName.length, namespaces.size());
068    for (int i = 0; i < namespaceName.length; i++) {
069      assertTrue(namespaces.contains(namespaceName[i]));
070    }
071  }
072
073  @Override
074  @Test
075  public void testBuildModel() throws Exception {
076    checkModel(buildTestModel());
077  }
078
079  @Override
080  @Test
081  public void testFromXML() throws Exception {
082    checkModel(fromXML(AS_XML));
083  }
084
085  @Override
086  @Test
087  public void testFromPB() throws Exception {
088    checkModel(fromPB(AS_PB));
089  }
090}