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