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.IOException;
23  import java.io.StringReader;
24  import java.io.StringWriter;
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.Base64;
31  import org.apache.hadoop.hbase.util.Bytes;
32  
33  import junit.framework.TestCase;
34  import org.junit.experimental.categories.Category;
35  
36  @Category(SmallTests.class)
37  public class TestScannerModel extends TestModelBase<ScannerModel> {
38    private static final byte[] START_ROW = Bytes.toBytes("abracadabra");
39    private static final byte[] END_ROW = Bytes.toBytes("zzyzx");
40    private static final byte[] COLUMN1 = Bytes.toBytes("column1");
41    private static final byte[] COLUMN2 = Bytes.toBytes("column2:foo");
42    private static final long START_TIME = 1245219839331L;
43    private static final long END_TIME = 1245393318192L;
44    private static final int CACHING = 1000;
45    private static final int BATCH = 100;
46  
47    public TestScannerModel() throws Exception {
48      super(ScannerModel.class);
49      AS_XML =
50        "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" +
51        "<Scanner batch=\"100\" caching=\"1000\" endRow=\"enp5eng=\" endTime=\"1245393318192\" " +
52        "maxVersions=\"2147483647\" startRow=\"YWJyYWNhZGFicmE=\" startTime=\"1245219839331\">" +
53        "<column>Y29sdW1uMQ==</column><column>Y29sdW1uMjpmb28=</column></Scanner>";
54  
55      AS_JSON =
56        "{\"batch\":100,\"caching\":1000,\"endRow\":\"enp5eng=\",\"endTime\":1245393318192,"+
57        "\"maxVersions\":2147483647,\"startRow\":\"YWJyYWNhZGFicmE=\",\"startTime\":1245219839331,"+
58        "\"column\":[\"Y29sdW1uMQ==\",\"Y29sdW1uMjpmb28=\"]}";
59  
60      AS_PB =
61        "CgthYnJhY2FkYWJyYRIFenp5engaB2NvbHVtbjEaC2NvbHVtbjI6Zm9vIGQo47qL554kMLDi57mf" +
62        "JDj/////B0joBw==";
63    }
64  
65    protected ScannerModel buildTestModel() {
66      ScannerModel model = new ScannerModel();
67      model.setStartRow(START_ROW);
68      model.setEndRow(END_ROW);
69      model.addColumn(COLUMN1);
70      model.addColumn(COLUMN2);
71      model.setStartTime(START_TIME);
72      model.setEndTime(END_TIME);
73      model.setBatch(BATCH);
74      model.setCaching(CACHING);
75      return model;
76    }
77  
78    protected void checkModel(ScannerModel model) {
79      assertTrue(Bytes.equals(model.getStartRow(), START_ROW));
80      assertTrue(Bytes.equals(model.getEndRow(), END_ROW));
81      boolean foundCol1 = false, foundCol2 = false;
82      for (byte[] column: model.getColumns()) {
83        if (Bytes.equals(column, COLUMN1)) {
84          foundCol1 = true;
85        } else if (Bytes.equals(column, COLUMN2)) {
86          foundCol2 = true;
87        }
88      }
89      assertTrue(foundCol1);
90      assertTrue(foundCol2);
91      assertEquals(model.getStartTime(), START_TIME);
92      assertEquals(model.getEndTime(), END_TIME);
93      assertEquals(model.getBatch(), BATCH);
94      assertEquals(model.getCaching(), CACHING);
95    }
96  
97  }
98