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 javax.xml.bind.JAXBContext;
25  
26  import org.apache.hadoop.hbase.testclassification.SmallTests;
27  import org.apache.hadoop.hbase.util.Bytes;
28  
29  import org.junit.experimental.categories.Category;
30  
31  @Category(SmallTests.class)
32  public class TestRowModel extends TestModelBase<RowModel> {
33  
34    private static final byte[] ROW1 = Bytes.toBytes("testrow1");
35    private static final byte[] COLUMN1 = Bytes.toBytes("testcolumn1");
36    private static final byte[] VALUE1 = Bytes.toBytes("testvalue1");
37    private static final long TIMESTAMP1 = 1245219839331L;
38  
39    private JAXBContext context;
40  
41    public TestRowModel() throws Exception {
42      super(RowModel.class);
43      AS_XML =
44        "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><Row key=\"dGVzdHJvdzE=\">" +
45        "<Cell column=\"dGVzdGNvbHVtbjE=\" timestamp=\"1245219839331\">dGVzdHZhbHVlMQ==</Cell></Row>";
46  
47      AS_JSON =
48        "{\"key\":\"dGVzdHJvdzE=\",\"Cell\":[{\"column\":\"dGVzdGNvbHVtbjE=\"," +
49        "\"timestamp\":1245219839331,\"$\":\"dGVzdHZhbHVlMQ==\"}]}";
50    }
51  
52    protected RowModel buildTestModel() {
53      RowModel model = new RowModel();
54      model.setKey(ROW1);
55      model.addCell(new CellModel(COLUMN1, TIMESTAMP1, VALUE1));
56      return model;
57    }
58  
59    protected void checkModel(RowModel model) {
60      assertTrue(Bytes.equals(ROW1, model.getKey()));
61      Iterator<CellModel> cells = model.getCells().iterator();
62      CellModel cell = cells.next();
63      assertTrue(Bytes.equals(COLUMN1, cell.getColumn()));
64      assertTrue(Bytes.equals(VALUE1, cell.getValue()));
65      assertTrue(cell.hasUserTimestamp());
66      assertEquals(cell.getTimestamp(), TIMESTAMP1);
67      assertFalse(cells.hasNext());
68    }
69  
70    @Override
71    public void testFromPB() throws Exception {
72      //do nothing row model has no PB
73    }
74  }
75