uk.ac.ebi.atlas.solr.query.PropertyValueQueryBuilderTest.java Source code

Java tutorial

Introduction

Here is the source code for uk.ac.ebi.atlas.solr.query.PropertyValueQueryBuilderTest.java

Source

/*
 * Copyright 2008-2013 Microarray Informatics Team, EMBL-European Bioinformatics Institute
 *
 * 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.
 *
 *
 * For further details of the Gene Expression Atlas project, including source code,
 * downloads and documentation, please see:
 *
 * http://gxa.github.com/gxa
 */

package uk.ac.ebi.atlas.solr.query;

import com.google.common.collect.Sets;
import org.apache.solr.client.solrj.SolrQuery;
import org.junit.Before;
import org.junit.Test;
import uk.ac.ebi.atlas.solr.query.builders.FacetedPropertyValueQueryBuilder;
import uk.ac.ebi.atlas.solr.query.builders.SolrQueryBuilder;

import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;

public class PropertyValueQueryBuilderTest {

    private FacetedPropertyValueQueryBuilder subject;

    @Before
    public void setUp() throws Exception {
        subject = new FacetedPropertyValueQueryBuilder();
    }

    @Test
    public void testBuildAutocompleteSuggestionQuery() throws Exception {
        // given
        SolrQuery solrQuery = subject.withSpecies("species").withBioentityTypes(Sets.newHashSet("ensgene"))
                .withPropertyNames(new String[] { "prototype1", "prototype2" })
                .buildPropertyValueAutocompleteQuery("geneX");

        // then
        assertThat(solrQuery.getQuery(),
                is(SolrQueryService.PROPERTY_EDGENGRAM_FIELD + ":\"geneX\" AND " + SolrQueryBuilder.SPECIES_FIELD
                        + ":\"species\" AND (" + SolrQueryService.BIOENTITY_TYPE_FIELD + ":\"ensgene\") AND ("
                        + SolrQueryService.PROPERTY_NAME_FIELD + ":\"prototype1\" OR "
                        + SolrQueryService.PROPERTY_NAME_FIELD + ":\"prototype2\")"));
    }

    @Test
    public void testBuildBioentityQuery() throws Exception {
        // given
        SolrQuery solrQuery = subject.withPropertyNames(new String[] { "prototype1", "prototype2" })
                .buildBioentityQuery("ENSMUS000000");

        // then
        assertThat(solrQuery.getQuery(),
                is(SolrQueryService.BIOENTITY_IDENTIFIER_FIELD + ":\"ENSMUS000000\" AND ("
                        + SolrQueryService.PROPERTY_NAME_FIELD + ":\"prototype1\" OR "
                        + SolrQueryService.PROPERTY_NAME_FIELD + ":\"prototype2\")"));

    }

}