Skip to main content
summaryrefslogtreecommitdiffstats
blob: 57d64aaa361dd7b1595908a67eee4f87b09dd488 (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
package org.eclipse.equinox.p2.cudf.tests;

import java.util.Collection;
import java.util.Iterator;
import junit.framework.TestCase;
import org.eclipse.equinox.p2.cudf.Parser;
import org.eclipse.equinox.p2.cudf.metadata.InstallableUnit;
import org.eclipse.equinox.p2.cudf.solver.*;

public class TestPascalExample extends TestCase {
	private ProfileChangeRequest pcr = null;

	protected void setUp() throws Exception {
		pcr = new Parser().parse(this.getClass().getClassLoader().getResource("testData/pascal.cudf").openStream());
	}

	public void testParanoid() {
		Object result = new SimplePlanner().getSolutionFor(pcr, new SolverConfiguration("paranoid", "1000c", true, false));
		if (result instanceof Collection) {
			Collection col = (Collection) result;
			assertEquals(col.toString(), 1, col.size());
			assertEquals(col.toString(), 1, getIU(col, "A").getVersion().getMajor());
		} else {
			fail("No result found!");
		}
	}

	public void testP2() {
		Object result = new SimplePlanner().getSolutionFor(pcr, new SolverConfiguration("p2", "1000c", true, false));
		if (result instanceof Collection) {
			Collection col = (Collection) result;
			assertEquals(col.toString(), 1, col.size());
			assertEquals(col.toString(), 1, getIU(col, "A").getVersion().getMajor());
		} else {
			fail("No result found!");
		}
	}

	//DISABLED
	//	public void testTrendy() {
	//		Object result = new SimplePlanner().getSolutionFor(pcr, new SolverConfiguration("trendy", "1000c", true, false));
	//		if (result instanceof Collection) {
	//			Collection col = (Collection) result;
	//			assertEquals(col.toString(), 1, col.size());
	//			assertEquals(col.toString(), 3, getIU(col, "A").getVersion().getMajor());
	//		} else {
	//			fail("No result found!");
	//		}
	//	}

	private InstallableUnit getIU(Collection col, String id) {
		Iterator it = col.iterator();
		while (it.hasNext()) {
			InstallableUnit iu = (InstallableUnit) it.next();
			if (id.equals(iu.getId()))
				return iu;
		}
		fail("Can't find: " + id);
		return null;
	}
}

Back to the top