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