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.assertFalse; 022import static org.junit.Assert.assertTrue; 023 024import java.util.Iterator; 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; 031import org.slf4j.Logger; 032import org.slf4j.LoggerFactory; 033 034@Category({RestTests.class, SmallTests.class}) 035public class TestTableSchemaModel extends TestModelBase<TableSchemaModel> { 036 037 @ClassRule 038 public static final HBaseClassTestRule CLASS_RULE = 039 HBaseClassTestRule.forClass(TestTableSchemaModel.class); 040 041 private static final Logger LOG = LoggerFactory.getLogger(TestTableSchemaModel.class); 042 043 public static final String TABLE_NAME = "testTable"; 044 private static final boolean IS_META = false; 045 private static final boolean IS_ROOT = false; 046 private static final boolean READONLY = false; 047 048 TestColumnSchemaModel testColumnSchemaModel; 049 050 public TestTableSchemaModel() throws Exception { 051 super(TableSchemaModel.class); 052 testColumnSchemaModel = new TestColumnSchemaModel(); 053 054 AS_XML = 055 "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + 056 "<TableSchema name=\"testTable\" IS_META=\"false\" IS_ROOT=\"false\" READONLY=\"false\">" + 057 "<ColumnSchema name=\"testcolumn\" BLOCKSIZE=\"16384\" BLOOMFILTER=\"NONE\" " + 058 "BLOCKCACHE=\"true\" COMPRESSION=\"GZ\" VERSIONS=\"1\" TTL=\"86400\" IN_MEMORY=\"false\"/>" + 059 "</TableSchema>"; 060 061 AS_PB = 062 "Cgl0ZXN0VGFibGUSEAoHSVNfTUVUQRIFZmFsc2USEAoHSVNfUk9PVBIFZmFsc2USEQoIUkVBRE9O" + 063 "TFkSBWZhbHNlGpcBCgp0ZXN0Y29sdW1uEhIKCUJMT0NLU0laRRIFMTYzODQSEwoLQkxPT01GSUxU" + 064 "RVISBE5PTkUSEgoKQkxPQ0tDQUNIRRIEdHJ1ZRIRCgtDT01QUkVTU0lPThICR1oSDQoIVkVSU0lP" + 065 "TlMSATESDAoDVFRMEgU4NjQwMBISCglJTl9NRU1PUlkSBWZhbHNlGICjBSABKgJHWigA"; 066 067 AS_JSON = 068 "{\"name\":\"testTable\",\"IS_META\":\"false\",\"IS_ROOT\":\"false\"," + 069 "\"READONLY\":\"false\",\"ColumnSchema\":[{\"name\":\"testcolumn\"," + 070 "\"BLOCKSIZE\":\"16384\",\"BLOOMFILTER\":\"NONE\",\"BLOCKCACHE\":\"true\"," + 071 "\"COMPRESSION\":\"GZ\",\"VERSIONS\":\"1\",\"TTL\":\"86400\",\"IN_MEMORY\":\"false\"}]}"; 072 } 073 074 @Override 075 protected TableSchemaModel buildTestModel() { 076 return buildTestModel(TABLE_NAME); 077 } 078 079 public TableSchemaModel buildTestModel(String name) { 080 TableSchemaModel model = new TableSchemaModel(); 081 model.setName(name); 082 model.__setIsMeta(IS_META); 083 model.__setIsRoot(IS_ROOT); 084 model.__setReadOnly(READONLY); 085 model.addColumnFamily(testColumnSchemaModel.buildTestModel()); 086 return model; 087 } 088 089 @Override 090 protected void checkModel(TableSchemaModel model) { 091 checkModel(model, TABLE_NAME); 092 } 093 094 public void checkModel(TableSchemaModel model, String tableName) { 095 assertEquals(model.getName(), tableName); 096 assertEquals(IS_META, model.__getIsMeta()); 097 assertEquals(IS_ROOT, model.__getIsRoot()); 098 assertEquals(READONLY, model.__getReadOnly()); 099 Iterator<ColumnSchemaModel> families = model.getColumns().iterator(); 100 assertTrue(families.hasNext()); 101 ColumnSchemaModel family = families.next(); 102 testColumnSchemaModel.checkModel(family); 103 assertFalse(families.hasNext()); 104 } 105 106 @Override 107 @Test 108 public void testBuildModel() throws Exception { 109 checkModel(buildTestModel()); 110 } 111 112 @Override 113 @Test 114 public void testFromXML() throws Exception { 115 checkModel(fromXML(AS_XML)); 116 } 117 118 @Override 119 @Test 120 public void testFromPB() throws Exception { 121 checkModel(fromPB(AS_PB)); 122 } 123 124} 125