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 = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" 046 + "<Namespaces><Namespace>testNamespace1</Namespace>" 047 + "<Namespace>testNamespace2</Namespace></Namespaces>"; 048 049 AS_PB = "Cg50ZXN0TmFtZXNwYWNlMQoOdGVzdE5hbWVzcGFjZTI="; 050 051 AS_JSON = "{\"Namespace\":[\"testNamespace1\",\"testNamespace2\"]}"; 052 } 053 054 @Override 055 protected NamespacesModel buildTestModel() { 056 return buildTestModel(NAMESPACE_NAME_1, NAMESPACE_NAME_2); 057 } 058 059 public NamespacesModel buildTestModel(String... namespaces) { 060 NamespacesModel model = new NamespacesModel(); 061 model.setNamespaces(Arrays.asList(namespaces)); 062 return model; 063 } 064 065 @Override 066 protected void checkModel(NamespacesModel model) { 067 checkModel(model, NAMESPACE_NAME_1, NAMESPACE_NAME_2); 068 } 069 070 public void checkModel(NamespacesModel model, String... namespaceName) { 071 List<String> namespaces = model.getNamespaces(); 072 assertEquals(namespaceName.length, namespaces.size()); 073 for (int i = 0; i < namespaceName.length; i++) { 074 assertTrue(namespaces.contains(namespaceName[i])); 075 } 076 } 077 078 @Override 079 @Test 080 public void testBuildModel() throws Exception { 081 checkModel(buildTestModel()); 082 } 083 084 @Override 085 @Test 086 public void testFromXML() throws Exception { 087 checkModel(fromXML(AS_XML)); 088 } 089 090 @Override 091 @Test 092 public void testFromPB() throws Exception { 093 checkModel(fromPB(AS_PB)); 094 } 095}