Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: f44fe8862e50afe54432591564b8afb68059553f (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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/*******************************************************************************
 * Copyright (c) 2008, 2017 IBM Corporation and others.
 *
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.equinox.p2.tests.directorywatcher;

import java.io.File;
import java.util.*;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.eclipse.equinox.p2.metadata.*;

/**
 * @since 1.0
 */
public class ProfileSynchronizerTest extends AbstractDirectoryWatcherTest {

	/*
	 * Constructor for the class.
	 */
	public ProfileSynchronizerTest(String name) {
		super(name);
	}

	/*
	 * Run all the tests in this class.
	 */
	public static Test suite() {
		return new TestSuite(ProfileSynchronizerTest.class);
	}

	public void test() {
		// empty test because the others aren't enabled yet
	}

	/*
	 * Test that we only try to install bundles with matching platform filters.
	 *
	 * TODO we don't want to test to see if the bundles are in the repo, but if
	 * the bundles are filtered when they are installed into a profile.
	 */
	public void _testPlatformFilter() {
		String base = "/testData/profileSynchronizer/";
		String[] extensions = new String[] {"bbb_1.0.0.jar", "bbb.linux_1.0.0.jar", "bbb.win32_1.0.0.jar"};
		Set<File> jars = new HashSet<>();
		for (int i = 0; i < extensions.length; i++)
			jars.add(getTestData("0.99", base + extensions[i]));
		File folder = getTempFolder();
		toRemove.add(folder);
		for (Iterator<File> iter = jars.iterator(); iter.hasNext();) {
			File next = iter.next();
			copy("1.0 " + next.getAbsolutePath(), next, new File(folder, next.getName()));
		}

		// We should have an empty repository because we haven't done anything yet
		TestRepositoryWatcher watcher = TestRepositoryWatcher.createWatcher(folder);
		assertEquals("2.0", 0, watcher.getInstallableUnits().length);
		assertEquals("2.1", 0, watcher.getArtifactKeys().length);

		watcher.poll();

		// which IUs we are expecting is dependent on which OS we are running
		Set<String> expected = new HashSet<>();
		expected.add("bbb");
		String os = System.getProperty("osgi.os");
		if ("win32".equals(os)) {
			expected.add("bbb.win32");
		} else if ("linux".equals(os)) {
			expected.add("bbb.linux");
		}

		IInstallableUnit[] ius = watcher.getInstallableUnits();
		assertEquals("3.0", expected.size(), ius.length);
		for (int i = 0; i < ius.length; i++)
			assertTrue("3.1 " + ius[i].getId(), expected.contains(ius[i].getId()));
		assertEquals("3.2", expected.size(), watcher.getArtifactKeys().length);
	}

	/*
	 * Test to ensure that we only try to install the highest version of singleton bundles
	 * where multiple versions exist.
	 *
	 * TODO we don't want to test to see if the bundles are in the repo, but if
	 * the bundles are filtered when they are installed into a profile.
	 */
	public void _testMultipleVersions() {
		File one = getTestData("0.1", "/testData/profileSynchronizer/ccc_1.0.0.jar");
		File two = getTestData("0.2", "/testData/profileSynchronizer/ccc_2.0.0.jar");
		File folder = getTempFolder();
		toRemove.add(folder);

		copy("1.0", one, new File(folder, one.getName()));
		copy("1.1", two, new File(folder, two.getName()));

		TestRepositoryWatcher watcher = TestRepositoryWatcher.createWatcher(folder);

		// We should have an empty repository because we haven't done anything yet
		assertEquals("2.0", 0, watcher.getInstallableUnits().length);
		assertEquals("2.1", 0, watcher.getArtifactKeys().length);

		watcher.poll();

		IInstallableUnit[] ius = watcher.getInstallableUnits();
		IArtifactKey[] artifacts = watcher.getArtifactKeys();
		assertEquals("3.0", 1, ius.length);
		assertEquals("3.1", "ccc", ius[0].getId());
		assertEquals("3.2", Version.create("2.0.0"), ius[0].getVersion());
		assertEquals("4.0", 1, artifacts.length);
	}

}

Back to the top