com.sindicetech.siren.solr.analysis.BaseSirenStreamTestCase.java Source code

Java tutorial

Introduction

Here is the source code for com.sindicetech.siren.solr.analysis.BaseSirenStreamTestCase.java

Source

/**
 * Copyright (c) 2014, Sindice Limited. All Rights Reserved.
 *
 * This file is part of the SIREn project.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.sindicetech.siren.solr.analysis;

import java.util.HashMap;
import java.util.Map;

import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
import org.apache.lucene.util.LuceneTestCase;
import org.apache.solr.schema.IndexSchema;

import com.sindicetech.siren.solr.BaseSolrServerTestCase;

public abstract class BaseSirenStreamTestCase extends BaseSolrServerTestCase {

    public void assertTokenStreamContents(final TokenStream stream, final String[] expectedImages)
            throws Exception {
        assertTrue("has TermAttribute", stream.hasAttribute(CharTermAttribute.class));
        final CharTermAttribute termAtt = stream.getAttribute(CharTermAttribute.class);

        stream.reset();
        for (int i = 0; i < expectedImages.length; i++) {
            stream.clearAttributes();
            assertTrue("token " + i + " does not exists", stream.incrementToken());

            assertEquals(expectedImages[i], termAtt.toString());
        }

        assertFalse("end of stream", stream.incrementToken());
        stream.end();
        stream.close();
    }

    public Map<String, String> getDefaultInitArgs() {
        final Map<String, String> args = new HashMap<String, String>();
        args.put(IndexSchema.LUCENE_MATCH_VERSION_PARAM, LuceneTestCase.TEST_VERSION_CURRENT.name());
        return args;
    }

}