krysalis-update/src/test/java/org/apache/depot/update/query QueryTests.java,NONE,1.1

Nick Chalko <[email protected]> Wed, 08 Dec 2004 09:07:18 +0000
Newsgroups gmane.comp.krysalis.cvs
Message-ID <[email protected]>
Update of /cvsroot/krysalis/krysalis-update/src/test/java/org/apache/depot/update/query
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24726/src/test/java/org/apache/depot/update/query

Added Files:
	QueryTests.java 
Log Message:
Copied from the apache incubator.

--- NEW FILE: QueryTests.java ---
/*
 * Copyright  2004 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.
 */

package org.apache.depot.update.query;

import junit.framework.TestCase;

import org.apache.depot.common.log.Logger;
import org.apache.depot.common.util.debug.DebugUtils;
import org.apache.depot.update.UpdateException;
import org.apache.depot.update.artifact.ArtifactGroup;
import org.apache.depot.update.artifact.ArtifactType;
import org.apache.depot.update.artifact.compare.VersionComparator;
import org.apache.depot.update.artifact.select.ReleaseLevelSelector;
import org.apache.depot.update.artifact.select.TypeSelector;
import org.apache.depot.update.artifact.select.VersionSelector;
import org.apache.depot.update.config.UpdaterConfig;
import org.apache.depot.update.impl.ArtifactUpdaterContext;
import org.apache.depot.update.impl.RepositorySetWrapper;
import org.apache.depot.update.repository.RepositorySet;
import org.apache.depot.update.util.UpdateConstants;
import org.apache.depot.update.util.select.logic.AndSelector;
import org.apache.depot.update.util.select.logic.OrSelector;
import org.apache.depot.version.impl.ApacheVersion;
import org.apache.depot.version.impl.data.ReleaseLevel;

/**
 * @author arb_jack
 */
public class QueryTests extends TestCase {

	private QueryEngine m_engine = null;
	private ArtifactUpdaterContext m_context = null;
	private RepositorySetWrapper m_repoSet = null;

	static {
		Logger.testInit();
		UpdaterConfig.configure();
	}

	public QueryTests(String name) {
		super(name);
	}

	public void setUp() throws Exception {
		m_context = ArtifactUpdaterContext.getTestContext();

		Logger.testInit();
		
		m_engine = new QueryEngine();

		m_repoSet = new RepositorySetWrapper(
				RepositorySet.getRepositorySet(UpdateConstants.MOCK, true),
				m_context);
		
		assertTrue("We have some repositories", !m_repoSet.isEmpty());
	}

	public void testQuery1() throws UpdateException {
		ArtifactQuery query = new ArtifactQuery(new ArtifactGroup("test"));
		perform(query);
	}
	/*
	public void testQuery2() throws UpdateException {
		ArtifactQuery query =
			new ArtifactQuery(
				new ArtifactGroup("junit"),
				new TypeSelector(ArtifactType.SOURCE_CODE),
				null,
				null);
		perform(query);
	}

	public void testQuery3() throws UpdateException {
		ArtifactQuery query =
			new ArtifactQuery(
				new ArtifactGroup("junit"),
				new VersionSelector(ApacheVersion.getTestVersion(1, 3)),
				null,
				null);
		performAndCount(query, 1, 2);
	}

	public void testQuery4() throws UpdateException {
		ArtifactQuery query =
			new ArtifactQuery(
				new ArtifactGroup("junit"),
				new AndSelector(
					new TypeSelector(ArtifactType.SOURCE_CODE),
					new VersionSelector(ApacheVersion.getTestVersion(1, 3))),
				null,
				null);
		performAndCount(query, 1, 1);
	}

	public void testQuery5() throws UpdateException {
		ArtifactQuery query =
			new ArtifactQuery(
				new ArtifactGroup("junit"),
				new OrSelector(
					new TypeSelector(ArtifactType.SOURCE_CODE),
					new VersionSelector(ApacheVersion.getTestVersion(1, 3))),
				null,
				null);
		performAndCount(query, 1, 11);
	}

	public void testQuery6() throws UpdateException {
		ArtifactQuery query =
			new ArtifactQuery(
				new ArtifactGroup("junit"),
				new OrSelector(
					new TypeSelector(ArtifactType.SOURCE_CODE),
					new VersionSelector(ApacheVersion.getTestVersion(1, 3))),
				VersionComparator.getInstance(),
				null);
		performAndCount(query, 10, 11);
	}

	public void testQuery7() throws UpdateException {
		ArtifactQuery query =
			new ArtifactQuery(
				new ArtifactGroup("junit"),
				new ReleaseLevelSelector(ReleaseLevel.RELEASE),
				VersionComparator.getInstance(),
				null);
		performAndCount(query, 10, 20);
	}

*/	private ArtifactResult performAndCountGroups(ArtifactQuery query, int size)
		throws UpdateException {
		ArtifactResult result = perform(query);

		assertEquals(
			"Size Expected",
			size,
			ArtifactResultHelper.groupCount(result));

		return result;
	}
	private ArtifactResult performAndCount(
		ArtifactQuery query,
		int groups,
		int artifacts)
		throws UpdateException {
		ArtifactResult result = perform(query);

		assertEquals(
			"Groups Expected",
			groups,
			ArtifactResultHelper.groupCount(result));

		assertEquals(
			"Artifacts Expected",
			artifacts,
			ArtifactResultHelper.artifactCount(result));

		return result;
	}

	private ArtifactResult perform(ArtifactQuery query) throws UpdateException {

		DebugUtils.dump(m_repoSet);
		
		ArtifactResult result = m_engine.queryRepositories(m_repoSet, query);

		Logger.getLogger().debug("Query : " + query.toString());
		
		DebugUtils.dump(query);
		DebugUtils.dump(result);

		assertTrue("Query results in OK", result.isSuccessful());
		assertFalse("Query results NOT empty", result.isEmpty());

		return result;
	}

	public static void main(String[] args) {
		junit.textui.TestRunner.run(QueryTests.class);
	}
}



-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now. 
http://productguide.itmanagersjournal.com/