Skip to main content
summaryrefslogtreecommitdiffstats
blob: ff122e2e442f4f5a38f8063526602a64078130d4 (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
75
76
77
/*******************************************************************************
 * Copyright (c) 2008, 2017 IBM Corporation 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:
 *     IBM Corporation - initial API and implementation
 *     EclipseSource - ongoing development
 *******************************************************************************/
package org.eclipse.equinox.p2.tests.ui.query;

import java.util.ArrayList;
import java.util.List;
import org.eclipse.equinox.internal.p2.ui.model.IIUElement;
import org.eclipse.equinox.p2.metadata.IInstallableUnit;
import org.eclipse.equinox.p2.metadata.Version;
import org.eclipse.equinox.p2.query.*;

/**
 * Tests for latest query. This has all the tests of the superclass,
 * plus some extras for testing the latest IU capabilities.
 */
public class LatestIUVersionElementWrapperTest extends AvailableIUWrapperTest {

	/**
	 * Returns the IU corresponding to the collected element.
	 */
	@Override
	protected IInstallableUnit getIU(Object collected) {
		if (collected instanceof IInstallableUnit)
			return (IInstallableUnit) collected;
		return ((IIUElement) collected).getIU();
	}

	/**
	 * Tests that only the latest version is collected.
	 */
	public void testCollectLatestIU() {
		IQuery<IInstallableUnit> latestIuVersionElementQuery = QueryUtil.createLatestIUQuery();
		IInstallableUnit unit1 = createIU("f1", Version.createOSGi(1, 0, 0));
		IInstallableUnit unit2 = createIU("f1", Version.createOSGi(1, 0, 1));
		List<IInstallableUnit> listOfIUs = new ArrayList<>();
		listOfIUs.add(unit1);
		listOfIUs.add(unit2);
		IQueryResult<IInstallableUnit> collector = latestIuVersionElementQuery.perform(listOfIUs.iterator());
		assertEquals("1.0", 1, queryResultSize(collector));
		IInstallableUnit collectedIU = getIU(collector.iterator().next());
		assertEquals("1.1", unit2, collectedIU);
	}

	public void testMultipleIUsAndVersions() {
		IQuery<IInstallableUnit> latestIuVersionElementQuery = QueryUtil.createLatestIUQuery();
		IInstallableUnit unit1 = createIU("A", Version.createOSGi(1, 0, 0));
		IInstallableUnit unit2 = createIU("A", Version.createOSGi(1, 0, 1));
		IInstallableUnit unit3 = createIU("B", Version.createOSGi(1, 0, 1));
		IInstallableUnit unit4 = createIU("B", Version.createOSGi(0, 1, 1));
		IInstallableUnit unit5 = createIU("C", Version.createOSGi(0, 1, 1));

		// We should get unit 2, unit 3 and unit 5 
		List<IInstallableUnit> listOfIUs = new ArrayList<>();
		listOfIUs.add(unit1);
		listOfIUs.add(unit2);
		listOfIUs.add(unit3);
		listOfIUs.add(unit4);
		listOfIUs.add(unit5);
		IQueryResult<IInstallableUnit> collector = latestIuVersionElementQuery.perform(listOfIUs.iterator());

		// Should be 3  units
		assertEquals("1.0", 3, queryResultSize(collector));
		assertContains("1.2", collector, unit2);
		assertContains("1.3", collector, unit3);
		assertContains("1.4", collector, unit5);

	}
}

Back to the top