Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: c6e58dd770ee0bf0d9bde26299d33b398a73f1ae (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
/*******************************************************************************
 * Copyright (c) 2010 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
 *******************************************************************************/
package org.eclipse.equinox.p2.tests.core;

import java.net.URI;
import java.net.URISyntaxException;
import org.eclipse.equinox.p2.core.*;
import org.eclipse.equinox.p2.engine.IProfileRegistry;
import org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager;
import org.eclipse.equinox.p2.tests.AbstractProvisioningTest;
import org.eclipse.equinox.p2.tests.TestActivator;
import org.osgi.framework.ServiceReference;

/**
 * Tests for {@link IProvisioningAgent} and related API.
 */
public class ProvisioningAgentTest extends AbstractProvisioningTest {
	/**
	 * See bug 307151 and bug 304899.
	 * @throws ProvisionException
	 * @throws URISyntaxException
	 */
	public void testMultipleAgents() throws ProvisionException, URISyntaxException {
		URI repoLocation = new URI("http://download.eclipse.org/eclipse/updates/3.6");
		URI p2location = getTempFolder().toURI();
		String PROFILE_ID = "testMultipleAgents";

		ServiceReference providerRef = TestActivator.context.getServiceReference(IProvisioningAgentProvider.class.getName());
		IProvisioningAgentProvider provider = (IProvisioningAgentProvider) TestActivator.context.getService(providerRef);

		IProvisioningAgent firstAgent = provider.createAgent(p2location);
		IProfileRegistry firstProfileRegistry = (IProfileRegistry) firstAgent.getService(IProfileRegistry.SERVICE_NAME);
		firstProfileRegistry.removeProfile(PROFILE_ID);
		firstProfileRegistry.addProfile(PROFILE_ID);
		IMetadataRepositoryManager firstMdrMgr = (IMetadataRepositoryManager) firstAgent.getService(IMetadataRepositoryManager.SERVICE_NAME);
		firstMdrMgr.addRepository(repoLocation);
		firstMdrMgr.setEnabled(repoLocation, false);
		firstAgent.stop();

		IProvisioningAgent secondAgent = provider.createAgent(p2location);
		IProfileRegistry secondProfileRegistry = (IProfileRegistry) secondAgent.getService(IProfileRegistry.SERVICE_NAME);
		secondProfileRegistry.removeProfile(PROFILE_ID);
		secondProfileRegistry.addProfile(PROFILE_ID);
		IMetadataRepositoryManager secondMdrMgr = (IMetadataRepositoryManager) secondAgent.getService(IMetadataRepositoryManager.SERVICE_NAME);
		secondMdrMgr.removeRepository(repoLocation);
		secondAgent.stop();

		TestActivator.context.ungetService(providerRef);

	}
}

Back to the top