View Javadoc

1   /*
2    *
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *     http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the License for the specific language governing permissions and
17   * limitations under the License.
18   */
19  
20  package org.apache.hadoop.hbase.rest.model;
21  
22  import java.util.Iterator;
23  
24  import org.apache.hadoop.hbase.testclassification.SmallTests;
25  import org.apache.hadoop.hbase.util.Bytes;
26  
27  import org.junit.experimental.categories.Category;
28  
29  @Category(SmallTests.class)
30  public class TestRowModel extends TestModelBase<RowModel> {
31  
32    private static final byte[] ROW1 = Bytes.toBytes("testrow1");
33    private static final byte[] COLUMN1 = Bytes.toBytes("testcolumn1");
34    private static final byte[] VALUE1 = Bytes.toBytes("testvalue1");
35    private static final long TIMESTAMP1 = 1245219839331L;
36  
37    public TestRowModel() throws Exception {
38      super(RowModel.class);
39      AS_XML =
40        "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><Row key=\"dGVzdHJvdzE=\">" +
41        "<Cell column=\"dGVzdGNvbHVtbjE=\" timestamp=\"1245219839331\">dGVzdHZhbHVlMQ==</Cell></Row>";
42  
43      AS_JSON =
44        "{\"key\":\"dGVzdHJvdzE=\",\"Cell\":[{\"column\":\"dGVzdGNvbHVtbjE=\"," +
45        "\"timestamp\":1245219839331,\"$\":\"dGVzdHZhbHVlMQ==\"}]}";
46    }
47  
48    @Override
49    protected RowModel buildTestModel() {
50      RowModel model = new RowModel();
51      model.setKey(ROW1);
52      model.addCell(new CellModel(COLUMN1, TIMESTAMP1, VALUE1));
53      return model;
54    }
55  
56    @Override
57    protected void checkModel(RowModel model) {
58      assertTrue(Bytes.equals(ROW1, model.getKey()));
59      Iterator<CellModel> cells = model.getCells().iterator();
60      CellModel cell = cells.next();
61      assertTrue(Bytes.equals(COLUMN1, cell.getColumn()));
62      assertTrue(Bytes.equals(VALUE1, cell.getValue()));
63      assertTrue(cell.hasUserTimestamp());
64      assertEquals(TIMESTAMP1, cell.getTimestamp());
65      assertFalse(cells.hasNext());
66    }
67  
68    @Override
69    public void testFromPB() throws Exception {
70      //do nothing row model has no PB
71    }
72  }
73