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