Skip to main content
summaryrefslogtreecommitdiffstats
blob: b296a9193bd5ab6448f6b6c48d63d8c1f2162273 (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
/*******************************************************************************
 * Copyright (c) 2013, 2018 Ericsson AB 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:
 *     Ericsson AB - initial API and implementation
 ******************************************************************************/
package org.eclipse.equinox.p2.tests.metadata;

import junit.framework.TestCase;
import org.eclipse.equinox.p2.metadata.IInstallableUnit;
import org.eclipse.equinox.p2.metadata.IRequirement;
import org.eclipse.equinox.p2.metadata.MetadataFactory;
import org.eclipse.equinox.p2.metadata.VersionRange;
import org.eclipse.equinox.p2.metadata.expression.ExpressionUtil;
import org.eclipse.equinox.p2.metadata.expression.IMatchExpression;

//These tests are not here to force the toString of a requirement.
//They are here to ensure that the toString of a requirement does not become unreadable because this ends up being presented in the p2 UI and in the tycho build.
//As such if there are better ways present all this information, by all mean change the test.
public class RequirementToString extends TestCase {
	public void testRequirementWithEmptyRange() {
		IRequirement req = MetadataFactory.createRequirement("expectedNameSpace", "expectedName", VersionRange.emptyRange, null, false, false);
		assertEquals("expectedNameSpace; expectedName 0.0.0", req.toString());
	}

	public void testStandardRequirement() {
		IRequirement req = MetadataFactory.createRequirement("expectedNameSpace", "expectedName", new VersionRange("[1.0.0, 2.0.0)"), null, false, false);
		assertEquals("expectedNameSpace; expectedName [1.0.0,2.0.0)", req.toString());
	}

	public void testPropertiesRequirement() {
		IRequirement req = MetadataFactory.createRequirement("expectedNameSpace", "(key=val)", null, 1, 1, true);
		assertEquals("expectedNameSpace; (key=val)", req.toString());
	}

	public void testFancyRequirement() {
		Object[] expressionParameters = new Object[] {"expectedId1", "expectedVersion1", "expectedId2", "expectedVersion2"};
		IMatchExpression<IInstallableUnit> iuMatcher = ExpressionUtil.getFactory().matchExpression(ExpressionUtil.parse("(id == $0 && version == $1) || (id == $2 && version == $3)"), expressionParameters);
		IRequirement req = MetadataFactory.createRequirement(iuMatcher, null, 1, 1, true);
		assertEquals("id == $0 && version == $1 || id == $2 && version == $3 (expectedId1, expectedVersion1, expectedId2, expectedVersion2)", req.toString().trim());
	}
}

Back to the top