|
Lines 10-35
Link Here
|
| 10 |
*******************************************************************************/ |
10 |
*******************************************************************************/ |
| 11 |
package org.eclipse.equinox.p2.tests.touchpoint.eclipse; |
11 |
package org.eclipse.equinox.p2.tests.touchpoint.eclipse; |
| 12 |
|
12 |
|
| 13 |
import org.eclipse.equinox.internal.p2.metadata.TouchpointInstruction; |
13 |
import java.lang.reflect.Field; |
| 14 |
|
|
|
| 15 |
import java.net.URI; |
14 |
import java.net.URI; |
|
|
15 |
import java.net.URISyntaxException; |
| 16 |
import java.util.HashMap; |
16 |
import java.util.HashMap; |
| 17 |
import java.util.Map; |
17 |
import java.util.Map; |
| 18 |
import org.eclipse.core.runtime.IStatus; |
18 |
import org.eclipse.core.runtime.IStatus; |
|
|
19 |
import org.eclipse.core.runtime.preferences.IPreferencesService; |
| 20 |
import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper; |
| 21 |
import org.eclipse.equinox.internal.p2.engine.SimpleProfileRegistry; |
| 22 |
import org.eclipse.equinox.internal.p2.metadata.TouchpointInstruction; |
| 19 |
import org.eclipse.equinox.internal.p2.touchpoint.eclipse.actions.AddRepositoryAction; |
23 |
import org.eclipse.equinox.internal.p2.touchpoint.eclipse.actions.AddRepositoryAction; |
| 20 |
import org.eclipse.equinox.internal.provisional.p2.core.Version; |
24 |
import org.eclipse.equinox.internal.provisional.p2.core.Version; |
| 21 |
import org.eclipse.equinox.internal.provisional.p2.core.repository.IRepository; |
25 |
import org.eclipse.equinox.internal.provisional.p2.core.repository.IRepository; |
| 22 |
import org.eclipse.equinox.internal.provisional.p2.director.ProfileChangeRequest; |
26 |
import org.eclipse.equinox.internal.provisional.p2.director.ProfileChangeRequest; |
| 23 |
import org.eclipse.equinox.internal.provisional.p2.engine.IProfile; |
27 |
import org.eclipse.equinox.internal.provisional.p2.engine.*; |
| 24 |
import org.eclipse.equinox.internal.provisional.p2.engine.ProvisioningContext; |
|
|
| 25 |
import org.eclipse.equinox.internal.provisional.p2.metadata.*; |
28 |
import org.eclipse.equinox.internal.provisional.p2.metadata.*; |
| 26 |
import org.eclipse.equinox.p2.tests.AbstractProvisioningTest; |
29 |
import org.eclipse.equinox.p2.tests.AbstractProvisioningTest; |
|
|
30 |
import org.eclipse.equinox.p2.tests.TestActivator; |
| 31 |
import org.osgi.service.prefs.BackingStoreException; |
| 32 |
import org.osgi.service.prefs.Preferences; |
| 27 |
|
33 |
|
| 28 |
/** |
34 |
/** |
| 29 |
* Tests for {@link org.eclipse.equinox.internal.p2.touchpoint.eclipse.actions.AddRepositoryAction}. |
35 |
* Tests for {@link org.eclipse.equinox.internal.p2.touchpoint.eclipse.actions.AddRepositoryAction}. |
| 30 |
*/ |
36 |
*/ |
| 31 |
public class AddRepositoryActionTest extends AbstractProvisioningTest { |
37 |
public class AddRepositoryActionTest extends AbstractProvisioningTest { |
| 32 |
private static final String TEST_LOCATION = "http://eclipse.org/eclipse/updates/AddRepositoryActionTest"; |
38 |
private static final String TEST_LOCATION = "http://eclipse.org/eclipse/updates/AddRepositoryActionTest"; |
|
|
39 |
private static final String KEY_URI = "uri"; |
| 33 |
AddRepositoryAction action; |
40 |
AddRepositoryAction action; |
| 34 |
private URI locationURI; |
41 |
private URI locationURI; |
| 35 |
|
42 |
|
|
Lines 50-59
Link Here
|
| 50 |
action = new AddRepositoryAction(); |
57 |
action = new AddRepositoryAction(); |
| 51 |
locationURI = new URI(TEST_LOCATION); |
58 |
locationURI = new URI(TEST_LOCATION); |
| 52 |
getArtifactRepositoryManager().removeRepository(locationURI); |
59 |
getArtifactRepositoryManager().removeRepository(locationURI); |
|
|
60 |
|
| 61 |
IProfile profile = getProfile(IProfileRegistry.SELF); |
| 62 |
if (profile != null) |
| 63 |
return; |
| 64 |
|
| 65 |
if (System.getProperty("eclipse.p2.profile") == null) { |
| 66 |
SimpleProfileRegistry profileRegistry = (SimpleProfileRegistry) ServiceHelper.getService(TestActivator.getContext(), IProfileRegistry.class.getName()); |
| 67 |
try { |
| 68 |
Field selfField = SimpleProfileRegistry.class.getDeclaredField("self"); //$NON-NLS-1$ |
| 69 |
selfField.setAccessible(true); |
| 70 |
Object self = selfField.get(profileRegistry); |
| 71 |
if (self == null) |
| 72 |
selfField.set(profileRegistry, "agent"); |
| 73 |
} catch (Throwable t) { |
| 74 |
fail(); |
| 75 |
} |
| 76 |
} |
| 77 |
profile = createProfile(IProfileRegistry.SELF); |
| 53 |
} |
78 |
} |
| 54 |
|
79 |
|
| 55 |
@Override |
80 |
@Override |
| 56 |
protected void tearDown() throws Exception { |
81 |
protected void tearDown() throws Exception { |
|
|
82 |
//Remove Self preference node |
| 83 |
try { |
| 84 |
IPreferencesService prefService = (IPreferencesService) ServiceHelper.getService(TestActivator.getContext(), IPreferencesService.class.getName()); |
| 85 |
prefService.getRootNode().node("/profile/_SELF_").removeNode(); |
| 86 |
} catch (BackingStoreException e) { |
| 87 |
// Exception can be ignored as we're simply attempting to cleanup for other tests |
| 88 |
} |
| 89 |
|
| 90 |
if (System.getProperty("eclipse.p2.profile") == null) { |
| 91 |
SimpleProfileRegistry profileRegistry = (SimpleProfileRegistry) ServiceHelper.getService(TestActivator.getContext(), IProfileRegistry.class.getName()); |
| 92 |
try { |
| 93 |
Field selfField = SimpleProfileRegistry.class.getDeclaredField("self"); //$NON-NLS-1$ |
| 94 |
selfField.setAccessible(true); |
| 95 |
Object self = selfField.get(profileRegistry); |
| 96 |
if (self.equals("agent")) |
| 97 |
selfField.set(profileRegistry, null); |
| 98 |
} catch (Throwable t) { |
| 99 |
// ignore as we still want to continue tidying up |
| 100 |
} |
| 101 |
} |
| 57 |
super.tearDown(); |
102 |
super.tearDown(); |
| 58 |
getArtifactRepositoryManager().removeRepository(locationURI); |
103 |
getArtifactRepositoryManager().removeRepository(locationURI); |
| 59 |
} |
104 |
} |
|
Lines 110-115
Link Here
|
| 110 |
assertTrue("1.1", result.isOK()); |
155 |
assertTrue("1.1", result.isOK()); |
| 111 |
} |
156 |
} |
| 112 |
|
157 |
|
|
|
158 |
public void testMultipleActionAdd() { |
| 159 |
Map args = getValidArguments(); |
| 160 |
IStatus result = action.execute(args); |
| 161 |
assertTrue("1.0", result.isOK()); |
| 162 |
|
| 163 |
result = action.execute(args); |
| 164 |
assertTrue("1.1", result.isOK()); |
| 165 |
|
| 166 |
result = action.undo(args); |
| 167 |
assertTrue("1.2", result.isOK()); |
| 168 |
|
| 169 |
assertTrue("2.0", locationExists(null, TEST_LOCATION)); |
| 170 |
} |
| 171 |
|
| 172 |
public void testUserWins() { |
| 173 |
try { |
| 174 |
getArtifactRepositoryManager().addRepository(new URI(TEST_LOCATION)); |
| 175 |
assertTrue("0.1", locationExists(null, TEST_LOCATION)); |
| 176 |
} catch (URISyntaxException e) { |
| 177 |
// Should not occur |
| 178 |
} |
| 179 |
|
| 180 |
Map args = getValidArguments(); |
| 181 |
IStatus result = action.execute(args); |
| 182 |
assertTrue("1.0", result.isOK()); |
| 183 |
|
| 184 |
result = action.undo(args); |
| 185 |
assertTrue("1.1", result.isOK()); |
| 186 |
|
| 187 |
assertTrue("2.0", locationExists(null, TEST_LOCATION)); |
| 188 |
} |
| 189 |
|
| 113 |
/** |
190 |
/** |
| 114 |
* Tests for install of an IU that adds a repository. |
191 |
* Tests for install of an IU that adds a repository. |
| 115 |
*/ |
192 |
*/ |
|
Lines 131-139
Link Here
|
| 131 |
|
208 |
|
| 132 |
//check that profile property is set |
209 |
//check that profile property is set |
| 133 |
profile = getProfile(id); |
210 |
profile = getProfile(id); |
| 134 |
String value = profile.getProperty(IProfile.PROP_METADATA_REPOSITORIES); |
211 |
// Get Preference node associated with the profile |
| 135 |
assertNull("2.0", value); |
212 |
IPreferencesService prefService = (IPreferencesService) ServiceHelper.getService(TestActivator.getContext(), IPreferencesService.class.getName()); |
| 136 |
value = profile.getProperty(IProfile.PROP_ARTIFACT_REPOSITORIES); |
213 |
Preferences pref = prefService.getRootNode().node("/profile/" + profile.getProfileId() + "/org.eclipse.equinox.p2.artifact.repository/repositories/" + getKey(TEST_LOCATION)); //$NON-NLS-1$ //$NON-NLS-2$ |
| 137 |
assertEquals("2.1", TEST_LOCATION, value); |
214 |
String value = pref.get(KEY_URI, null); |
|
|
215 |
|
| 216 |
assertEquals("2.0", value, TEST_LOCATION); |
| 217 |
} |
| 218 |
|
| 219 |
/* |
| 220 |
* Modified from AbstractRepositoryManager |
| 221 |
*/ |
| 222 |
private String getKey(String location) { |
| 223 |
String key = location.replace('/', '_'); |
| 224 |
//remove trailing slash |
| 225 |
if (key.endsWith("_")) //$NON-NLS-1$ |
| 226 |
key = key.substring(0, key.length() - 1); |
| 227 |
return key; |
| 228 |
} |
| 229 |
|
| 230 |
private boolean locationExists(IProfile profile, String location) { |
| 231 |
IPreferencesService prefService = (IPreferencesService) ServiceHelper.getService(TestActivator.getContext(), IPreferencesService.class.getName()); |
| 232 |
Preferences pref; |
| 233 |
if (profile != null) |
| 234 |
pref = prefService.getRootNode().node("/profile/" + profile.getProfileId() + "/org.eclipse.equinox.p2.artifactRepositories/repositories/" + getKey(location)); |
| 235 |
else |
| 236 |
pref = prefService.getRootNode().node("/profile/_SELF_/org.eclipse.equinox.p2.artifact.repository/repositories/" + getKey(location)); |
| 237 |
if (location.equals(pref.get(KEY_URI, null))) |
| 238 |
return true; |
| 239 |
return false; |
| 138 |
} |
240 |
} |
| 139 |
} |
241 |
} |