View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package org.apache.hadoop.hbase.rest.model;
19  
20  import org.apache.hadoop.hbase.testclassification.SmallTests;
21  import org.apache.hadoop.hbase.util.Bytes;
22  import org.junit.experimental.categories.Category;
23  
24  @Category(SmallTests.class)
25  public class TestScannerModel extends TestModelBase<ScannerModel> {
26    private static final String PRIVATE = "private";
27    private static final String PUBLIC = "public";
28    private static final byte[] START_ROW = Bytes.toBytes("abracadabra");
29    private static final byte[] END_ROW = Bytes.toBytes("zzyzx");
30    private static final byte[] COLUMN1 = Bytes.toBytes("column1");
31    private static final byte[] COLUMN2 = Bytes.toBytes("column2:foo");
32    private static final long START_TIME = 1245219839331L;
33    private static final long END_TIME = 1245393318192L;
34    private static final int CACHING = 1000;
35    private static final int BATCH = 100;
36    private static final boolean CACHE_BLOCKS = false;
37  
38    public TestScannerModel() throws Exception {
39      super(ScannerModel.class);
40      AS_XML = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>"
41          + "<Scanner batch=\"100\" cacheBlocks=\"false\" caching=\"1000\" endRow=\"enp5eng=\" "
42          + "endTime=\"1245393318192\" maxVersions=\"2147483647\" startRow=\"YWJyYWNhZGFicmE=\" "
43          + "startTime=\"1245219839331\">"
44          + "<column>Y29sdW1uMQ==</column><column>Y29sdW1uMjpmb28=</column>"
45          + "<labels>private</labels><labels>public</labels>"
46          + "</Scanner>";
47  
48      AS_JSON = "{\"startRow\":\"YWJyYWNhZGFicmE=\",\"endRow\":\"enp5eng=\",\"column\":"
49          + "[\"Y29sdW1uMQ==\",\"Y29sdW1uMjpmb28=\"],\"batch\":100,\"startTime\":1245219839331,"
50          + "\"endTime\":1245393318192,\"filter\":null,\"maxVersions\":2147483647,"
51          + "\"caching\":1000,\"labels\":[\"private\",\"public\"],\"cacheBlocks\":false}";
52  
53      AS_PB = "CgthYnJhY2FkYWJyYRIFenp5engaB2NvbHVtbjEaC2NvbHVtbjI6Zm9vIGQo47qL554kMLDi57mf"
54          + "JDj/////B0joB1IHcHJpdmF0ZVIGcHVibGljWAA=";
55    }
56  
57    @Override
58    protected ScannerModel buildTestModel() {
59      ScannerModel model = new ScannerModel();
60      model.setStartRow(START_ROW);
61      model.setEndRow(END_ROW);
62      model.addColumn(COLUMN1);
63      model.addColumn(COLUMN2);
64      model.setStartTime(START_TIME);
65      model.setEndTime(END_TIME);
66      model.setBatch(BATCH);
67      model.setCaching(CACHING);
68      model.addLabel(PRIVATE);
69      model.addLabel(PUBLIC);
70      model.setCacheBlocks(CACHE_BLOCKS);
71      return model;
72    }
73  
74    @Override
75    protected void checkModel(ScannerModel model) {
76      assertTrue(Bytes.equals(model.getStartRow(), START_ROW));
77      assertTrue(Bytes.equals(model.getEndRow(), END_ROW));
78      boolean foundCol1 = false, foundCol2 = false;
79      for (byte[] column : model.getColumns()) {
80        if (Bytes.equals(column, COLUMN1)) {
81          foundCol1 = true;
82        } else if (Bytes.equals(column, COLUMN2)) {
83          foundCol2 = true;
84        }
85      }
86      assertTrue(foundCol1);
87      assertTrue(foundCol2);
88      assertEquals(START_TIME, model.getStartTime());
89      assertEquals(END_TIME, model.getEndTime());
90      assertEquals(BATCH, model.getBatch());
91      assertEquals(CACHING, model.getCaching());
92      assertEquals(CACHE_BLOCKS, model.getCacheBlocks());
93      boolean foundLabel1 = false;
94      boolean foundLabel2 = false;
95      if (model.getLabels() != null && model.getLabels().size() > 0) {
96        for (String label : model.getLabels()) {
97          if (label.equals(PRIVATE)) {
98            foundLabel1 = true;
99          } else if (label.equals(PUBLIC)) {
100           foundLabel2 = true;
101         }
102       }
103       assertTrue(foundLabel1);
104       assertTrue(foundLabel2);
105     }
106   }
107 }