Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: c5f35eef072a009fc8838357b81ce8a980f3b8d9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*******************************************************************************
 * Copyright (c) 2009 Cloudsmith Inc. and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Cloudsmith Inc. - initial API and implementation
 *******************************************************************************/
package org.eclipse.equinox.p2.tests.ql;

import java.net.URI;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.equinox.p2.metadata.*;
import org.eclipse.equinox.p2.query.*;
import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository;
import org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager;
import org.eclipse.equinox.p2.tests.AbstractProvisioningTest;

public class TestIndexes extends AbstractProvisioningTest {

	public void testIdIndexSimple() throws Exception {
		IMetadataRepository repo = getMDR("/testData/galileoM7");
		IQuery<IInstallableUnit> query = QueryUtil.createQuery("select(x | x.id == $0)", "org.eclipse.sdk.feature.group");
		IQueryResult<IInstallableUnit> result = repo.query(query, getMonitor());
		assertEquals(queryResultSize(result), 1);
	}

	public void testIdIndexWithOR() throws Exception {
		IMetadataRepository repo = getMDR("/testData/galileoM7");
		IQuery<IInstallableUnit> query = QueryUtil.createQuery("select(x | x.id == $0 || x.id == $1)", "org.eclipse.sdk.feature.group", "org.eclipse.sdk.feature.jar");
		IQueryResult<IInstallableUnit> result = repo.query(query, getMonitor());
		assertEquals(queryResultSize(result), 2);
	}

	public void testIdIndexWithNot() throws Exception {
		IMetadataRepository repo = getMDR("/testData/galileoM7");
		IQuery<IInstallableUnit> query = QueryUtil.createQuery("select(x | x.id == $0 || x.id != $1)", "org.eclipse.sdk.feature.group", "org.eclipse.sdk.feature.jar");
		IQueryResult<IInstallableUnit> result = repo.query(query, getMonitor());
		assertEquals(queryResultSize(result), 3464);
	}

	public void testCapabilityIndexSimple() throws Exception {
		IMetadataRepository repo = getMDR("/testData/galileoM7");
		IQuery<IInstallableUnit> query = QueryUtil.createQuery("select(x | x.providedCapabilities.exists(pc | pc.namespace == 'org.eclipse.equinox.p2.iu' && pc.name == $0))", "org.eclipse.core.resources");
		IQueryResult<IInstallableUnit> result = repo.query(query, getMonitor());
		assertEquals(queryResultSize(result), 1);
	}

	public void testCapabilityIndexMatches() throws Exception {
		IMetadataRepository repo = getMDR("/testData/galileoM7");
		IRequirement requirement = MetadataFactory.createRequirement("org.eclipse.equinox.p2.iu", "org.eclipse.core.resources", null, null, 1, 2, true);
		IQuery<IInstallableUnit> query = QueryUtil.createQuery("select(x | x ~= $0)", requirement);
		IQueryResult<IInstallableUnit> result = repo.query(query, getMonitor());
		assertEquals(queryResultSize(result), 1);
	}

	public void testComplexIndexMatches() throws Exception {
		IMetadataRepository repo = getMDR("/testData/galileoM7");
		IQuery<IInstallableUnit> query = QueryUtil.createMatchQuery("id ~= /*.feature.group/ && properties['org.eclipse.equinox.p2.type.group'] == true && providedCapabilities.exists(p | p.namespace == 'org.eclipse.equinox.p2.iu' && p.name == id)");
		IQueryResult<IInstallableUnit> result = repo.query(query, getMonitor());
		assertEquals(queryResultSize(result), 487);
	}

	private IMetadataRepository getMDR(String uri) throws Exception {
		URI metadataRepo = getTestData("1.1", uri).toURI();

		IMetadataRepositoryManager metadataManager = (IMetadataRepositoryManager) getAgent().getService(IMetadataRepositoryManager.SERVICE_NAME);
		assertNotNull(metadataManager);

		return metadataManager.loadRepository(metadataRepo, new NullProgressMonitor());
	}
}

Back to the top