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 org.apache.hadoop.hbase.testclassification.SmallTests;
23  import org.apache.hadoop.hbase.util.Bytes;
24  
25  import org.junit.experimental.categories.Category;
26  
27  @Category(SmallTests.class)
28  public class TestCellModel extends TestModelBase<CellModel> {
29  
30    private static final long TIMESTAMP = 1245219839331L;
31    private static final byte[] COLUMN = Bytes.toBytes("testcolumn");
32    private static final byte[] VALUE = Bytes.toBytes("testvalue");
33  
34    public TestCellModel() throws Exception {
35      super(CellModel.class);
36      AS_XML =
37        "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><Cell " +
38            "column=\"dGVzdGNvbHVtbg==\" timestamp=\"1245219839331\">dGVzdHZhbHVl</Cell>";
39      AS_PB =
40        "Egp0ZXN0Y29sdW1uGOO6i+eeJCIJdGVzdHZhbHVl";
41  
42      AS_JSON =
43        "{\"column\":\"dGVzdGNvbHVtbg==\",\"timestamp\":1245219839331,\"$\":\"dGVzdHZhbHVl\"}";
44    }
45  
46    protected CellModel buildTestModel() {
47      CellModel model = new CellModel();
48      model.setColumn(COLUMN);
49      model.setTimestamp(TIMESTAMP);
50      model.setValue(VALUE);
51      return model;
52    }
53  
54    protected void checkModel(CellModel model) {
55      assertTrue(Bytes.equals(model.getColumn(), COLUMN));
56      assertTrue(Bytes.equals(model.getValue(), VALUE));
57      assertTrue(model.hasUserTimestamp());
58      assertEquals(model.getTimestamp(), TIMESTAMP);
59    }
60  
61    public void testBuildModel() throws Exception {
62      checkModel(buildTestModel());
63    }
64  
65    public void testFromXML() throws Exception {
66      checkModel(fromXML(AS_XML));
67    }
68  
69    public void testFromPB() throws Exception {
70      checkModel(fromPB(AS_PB));
71    }
72  
73  }
74