01: package org.apache.lucene.analysis.payloads;
02:
03: /**
04: * Copyright 2004 The Apache Software Foundation
05: *
06: * Licensed under the Apache License, Version 2.0 (the "License");
07: * you may not use this file except in compliance with the License.
08: * You may obtain a copy of the License at
09: *
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:
19: import junit.framework.TestCase;
20: import org.apache.lucene.analysis.Token;
21: import org.apache.lucene.analysis.WhitespaceTokenizer;
22: import org.apache.lucene.index.Payload;
23:
24: import java.io.IOException;
25: import java.io.StringReader;
26:
27: public class TokenOffsetPayloadTokenFilterTest extends TestCase {
28:
29: public TokenOffsetPayloadTokenFilterTest(String s) {
30: super (s);
31: }
32:
33: protected void setUp() {
34: }
35:
36: protected void tearDown() {
37:
38: }
39:
40: public void test() throws IOException {
41: String test = "The quick red fox jumped over the lazy brown dogs";
42:
43: TokenOffsetPayloadTokenFilter nptf = new TokenOffsetPayloadTokenFilter(
44: new WhitespaceTokenizer(new StringReader(test)));
45: Token tok = new Token();
46: int count = 0;
47: while ((tok = nptf.next(tok)) != null) {
48: assertTrue("tok is null and it shouldn't be", tok != null);
49: Payload pay = tok.getPayload();
50: assertTrue("pay is null and it shouldn't be", pay != null);
51: byte[] data = pay.getData();
52: int start = PayloadHelper.decodeInt(data, 0);
53: assertTrue(start + " does not equal: " + tok.startOffset(),
54: start == tok.startOffset());
55: int end = PayloadHelper.decodeInt(data, 4);
56: assertTrue(end + " does not equal: " + tok.endOffset(),
57: end == tok.endOffset());
58: count++;
59: }
60: assertTrue(count + " does not equal: " + 10, count == 10);
61:
62: }
63:
64: }
|