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    private static final boolean CACHE_BLOCKS = false;
39  
40    public TestScannerModel() throws Exception {
41      super(ScannerModel.class);
42      AS_XML = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>"
43          + "<Scanner batch=\"100\" cacheBlocks=\"false\" caching=\"1000\" endRow=\"enp5eng=\" "
44          + "endTime=\"1245393318192\" maxVersions=\"2147483647\" startRow=\"YWJyYWNhZGFicmE=\" "
45          + "startTime=\"1245219839331\">"
46          + "<column>Y29sdW1uMQ==</column><column>Y29sdW1uMjpmb28=</column>"
47          + "<label>private</label><label>public</label>"
48          + "</Scanner>";
49  
50      AS_JSON = "{\"batch\":100,\"caching\":1000,\"cacheBlocks\":false,\"endRow\":\"enp5eng=\","
51          + "\"endTime\":1245393318192,\"maxVersions\":2147483647,\"startRow\":\"YWJyYWNhZGFicmE=\","
52          + "\"startTime\":1245219839331,\"column\":[\"Y29sdW1uMQ==\",\"Y29sdW1uMjpmb28=\"],"
53          +"\"labels\":[\"private\",\"public\"]"
54          +"}";
55  
56      AS_PB = "CgthYnJhY2FkYWJyYRIFenp5engaB2NvbHVtbjEaC2NvbHVtbjI6Zm9vIGQo47qL554kMLDi57mf"
57          + "JDj/////B0joB1IHcHJpdmF0ZVIGcHVibGljWAA=";
58    }
59  
60    protected ScannerModel buildTestModel() {
61      ScannerModel model = new ScannerModel();
62      model.setStartRow(START_ROW);
63      model.setEndRow(END_ROW);
64      model.addColumn(COLUMN1);
65      model.addColumn(COLUMN2);
66      model.setStartTime(START_TIME);
67      model.setEndTime(END_TIME);
68      model.setBatch(BATCH);
69      model.setCaching(CACHING);
70      model.addLabel(PRIVATE);
71      model.addLabel(PUBLIC);
72      model.setCacheBlocks(CACHE_BLOCKS);
73      return model;
74    }
75  
76    protected void checkModel(ScannerModel model) {
77      assertTrue(Bytes.equals(model.getStartRow(), START_ROW));
78      assertTrue(Bytes.equals(model.getEndRow(), END_ROW));
79      boolean foundCol1 = false, foundCol2 = false;
80      for (byte[] column : model.getColumns()) {
81        if (Bytes.equals(column, COLUMN1)) {
82          foundCol1 = true;
83        } else if (Bytes.equals(column, COLUMN2)) {
84          foundCol2 = true;
85        }
86      }
87      assertTrue(foundCol1);
88      assertTrue(foundCol2);
89      assertEquals(model.getStartTime(), START_TIME);
90      assertEquals(model.getEndTime(), END_TIME);
91      assertEquals(model.getBatch(), BATCH);
92      assertEquals(model.getCaching(), CACHING);
93      assertEquals(model.getCacheBlocks(), CACHE_BLOCKS);
94      boolean foundLabel1 = false;
95      boolean foundLabel2 = false;
96      if (model.getLabels() != null && model.getLabels().size() > 0) {
97        for (String label : model.getLabels()) {
98          if (label.equals(PRIVATE)) {
99            foundLabel1 = true;
100         } else if (label.equals(PUBLIC)) {
101           foundLabel2 = true;
102         }
103       }
104       assertTrue(foundLabel1);
105       assertTrue(foundLabel2);
106     }
107   }
108 
109 }