From d2abff1bda0f547c7b1b0c7387ab1c154a2cadcc Mon Sep 17 00:00:00 2001 From: "Edwin L. Punzalan" Date: Wed, 4 Jan 2006 03:09:05 +0000 Subject: [PATCH] PR: MRM-54 Added unit tests and fixed missing implements in AbstractCompoundQuery git-svn-id: https://svn.apache.org/repos/asf/maven/repository-manager/trunk@365806 13f79535-47bb-0310-9956-ffa450edef68 --- .../indexing/query/AbstractCompoundQuery.java | 1 + .../repository/indexing/query/QueryTest.java | 84 +++++++++++++++++++ 2 files changed, 85 insertions(+) create mode 100644 maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/query/QueryTest.java diff --git a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/query/AbstractCompoundQuery.java b/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/query/AbstractCompoundQuery.java index 0ecc7931c..dd77d9c14 100644 --- a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/query/AbstractCompoundQuery.java +++ b/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/query/AbstractCompoundQuery.java @@ -25,6 +25,7 @@ import java.util.List; * @author Edwin Punzalan */ public abstract class AbstractCompoundQuery + implements Query { protected List queries; diff --git a/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/query/QueryTest.java b/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/query/QueryTest.java new file mode 100644 index 000000000..b1c53daf6 --- /dev/null +++ b/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/query/QueryTest.java @@ -0,0 +1,84 @@ +package org.apache.maven.repository.indexing.query; + +import junit.framework.*; + +/* + * Copyright 2001-2005 The Apache Software Foundation. + * + * 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. + */ + +/** + * + * @author Edwin Punzalan + */ +public class QueryTest extends TestCase +{ + public void testSinglePhraseQueryObject() + { + SinglePhraseQuery query = new SinglePhraseQuery( "Field", "Value" ); + assertTrue( query instanceof Query ); + assertEquals( "Field", query.getField() ); + assertEquals( "Value", query.getValue() ); + } + + public void testCompoundQueries() + { + RequiredQuery rQuery = new RequiredQuery(); + assertTrue( rQuery instanceof Query ); + rQuery.add( new SinglePhraseQuery( "r1Field", "r1Value" ) ); + rQuery.add( new SinglePhraseQuery( "r2Field", "r2Value" ) ); + + OptionalQuery oQuery = new OptionalQuery(); + oQuery.add( new SinglePhraseQuery( "oField", "oValue" ) ); + + RequiredQuery all = new RequiredQuery(); + all.add( rQuery ); + all.add( oQuery ); + assertEquals( 2, all.getQueryList().size() ); + + for( int ctr = 0; ctr < all.getQueryList().size(); ctr++ ) + { + Query query = (Query) all.getQueryList().get( ctr ); + switch ( ctr ) + { + case 0: + assertTrue( query instanceof RequiredQuery ); + rQuery = (RequiredQuery) query; + assertEquals( 2, rQuery.getQueryList().size() ); + query = (Query) rQuery.getQueryList().get( 0 ); + assertTrue( query instanceof SinglePhraseQuery ); + SinglePhraseQuery sQuery = (SinglePhraseQuery) query; + assertEquals( "r1Field", sQuery.getField() ); + assertEquals( "r1Value", sQuery.getValue() ); + query = (Query) rQuery.getQueryList().get( 1 ); + assertTrue( query instanceof SinglePhraseQuery ); + sQuery = (SinglePhraseQuery) query; + assertEquals( "r2Field", sQuery.getField() ); + assertEquals( "r2Value", sQuery.getValue() ); + break; + case 1: + assertTrue( query instanceof OptionalQuery ); + oQuery = (OptionalQuery) query; + assertEquals( 1, oQuery.getQueryList().size() ); + query = (Query) oQuery.getQueryList().get( 0 ); + assertTrue( query instanceof SinglePhraseQuery ); + sQuery = (SinglePhraseQuery) query; + assertEquals( "oField", sQuery.getField() ); + assertEquals( "oValue", sQuery.getValue() ); + break; + } + } + } +} -- 2.39.5