Added
Link Here
|
1 |
/******************************************************************************* |
2 |
* Copyright (c) 2008 IBM Corporation and others. All rights reserved. This |
3 |
* program and the accompanying materials are made available under the terms of |
4 |
* the Eclipse Public License v1.0 which accompanies this distribution, and is |
5 |
* available at http://www.eclipse.org/legal/epl-v10.html |
6 |
* |
7 |
* Contributors: IBM Corporation - initial API and implementation |
8 |
******************************************************************************/ |
9 |
package org.eclipse.equinox.p2.tests.director; |
10 |
|
11 |
import java.io.File; |
12 |
import java.net.MalformedURLException; |
13 |
import java.net.URL; |
14 |
import java.util.HashMap; |
15 |
import java.util.Map; |
16 |
import org.eclipse.core.runtime.CoreException; |
17 |
import org.eclipse.equinox.app.IApplicationContext; |
18 |
import org.eclipse.equinox.internal.p2.director.app.Application; |
19 |
import org.eclipse.equinox.p2.tests.AbstractProvisioningTest; |
20 |
import org.osgi.framework.Bundle; |
21 |
|
22 |
/** |
23 |
* Various automated tests of the {@link IDirector} API. |
24 |
*/ |
25 |
public class DirectorAppTest extends AbstractProvisioningTest { |
26 |
|
27 |
/** |
28 |
* runs default director app. |
29 |
*/ |
30 |
private void runDirectorApp(final String message, final URL metadata, final URL artifact, final URL destination, final String installIU) throws Exception { |
31 |
Application application = new Application(); |
32 |
application.start(new IApplicationContext() { |
33 |
|
34 |
public void applicationRunning() { |
35 |
} |
36 |
|
37 |
public Map getArguments() { |
38 |
Map arguments = new HashMap(); |
39 |
|
40 |
arguments.put(IApplicationContext.APPLICATION_ARGS, new String[] {"-metadataRepository", metadata.toExternalForm(), "-artifactRepository", artifact.toExternalForm(), "-installIU", installIU, "-destination", destination.toExternalForm(), "-profile", "PlatformSDKProfile", "-profileProperties", "org.eclipse.update.install.features=true", "-bundlepool", destination.toExternalForm(), "-roaming", "-vmargs", "-Declipse.p2.data.area=c:/install_dest/p2"}); |
41 |
|
42 |
return arguments; |
43 |
} |
44 |
|
45 |
public String getBrandingApplication() { |
46 |
return null; |
47 |
} |
48 |
|
49 |
public Bundle getBrandingBundle() { |
50 |
return null; |
51 |
} |
52 |
|
53 |
public String getBrandingDescription() { |
54 |
return null; |
55 |
} |
56 |
|
57 |
public String getBrandingId() { |
58 |
return null; |
59 |
} |
60 |
|
61 |
public String getBrandingName() { |
62 |
return null; |
63 |
} |
64 |
|
65 |
public String getBrandingProperty(String key) { |
66 |
return null; |
67 |
} |
68 |
}); |
69 |
} |
70 |
|
71 |
public void testRepoCreationBothInvalid() { |
72 |
//Setup: Create the folders |
73 |
File metadataRepo = new File(getTempFolder(), "DirectorApp Metadata"); |
74 |
File artifactRepo = new File(getTempFolder(), "DirectorApp Artifact"); |
75 |
File destinationRepo = new File(getTempFolder(), "DirectorApp Destination"); |
76 |
String installIU = "invalidIU"; |
77 |
|
78 |
//Setup: ensure folders do not exist |
79 |
delete(metadataRepo); |
80 |
delete(artifactRepo); |
81 |
delete(destinationRepo); |
82 |
|
83 |
try { |
84 |
runDirectorApp("1.0", metadataRepo.toURL(), artifactRepo.toURL(), destinationRepo.toURL(), installIU); |
85 |
} catch (MalformedURLException e) { |
86 |
fail("1.1", e); |
87 |
} catch (CoreException e) { |
88 |
//fall through |
89 |
} catch (Exception e) { |
90 |
fail("1.2", e); |
91 |
} |
92 |
|
93 |
//ensures that repositories have not been mistakenly created |
94 |
assertTrue("1.3", !metadataRepo.exists()); |
95 |
assertTrue("1.4", !artifactRepo.exists()); |
96 |
|
97 |
//Cleanup: delete the folders |
98 |
delete(metadataRepo); |
99 |
delete(artifactRepo); |
100 |
delete(destinationRepo); |
101 |
} |
102 |
|
103 |
public void testRepoCreationMetadataInvalid() { |
104 |
//Setup: create repos |
105 |
File metadataRepo = new File(getTempFolder(), "DirectorApp Metadata"); |
106 |
File artifactRepo = getTestData("2.0", "/testData/mirror/mirrorSourceRepo1"); |
107 |
File destinationRepo = new File(getTempFolder(), "DirectorApp Destination"); |
108 |
String installIU = "invalidIU"; |
109 |
|
110 |
//Setup: ensure folders do not exist |
111 |
delete(metadataRepo); |
112 |
delete(destinationRepo); |
113 |
|
114 |
try { |
115 |
runDirectorApp("2.1", metadataRepo.toURL(), artifactRepo.toURL(), destinationRepo.toURL(), installIU); |
116 |
} catch (MalformedURLException e) { |
117 |
fail("2.2", e); |
118 |
} catch (CoreException e) { |
119 |
//fall through |
120 |
} catch (Exception e) { |
121 |
fail("2.3", e); |
122 |
} |
123 |
|
124 |
//ensures that repository has not been mistakenly created |
125 |
assertTrue("2.4", !metadataRepo.exists()); |
126 |
assertTrue("2.5", artifactRepo.exists()); |
127 |
|
128 |
//Cleanup: delete the folders |
129 |
delete(metadataRepo); |
130 |
delete(destinationRepo); |
131 |
} |
132 |
|
133 |
public void testRepoCreationArtifactInvalid() { |
134 |
//Setup: create repos |
135 |
File metadataRepo = getTestData("3.0", "/testData/mirror/mirrorSourceRepo1"); |
136 |
File artifactRepo = new File(getTempFolder(), "DirectorApp Artifact"); |
137 |
File destinationRepo = new File(getTempFolder(), "DirectorApp Destination"); |
138 |
String installIU = "invalidIU"; |
139 |
|
140 |
//Setup: ensure folders do not exist |
141 |
delete(artifactRepo); |
142 |
delete(destinationRepo); |
143 |
|
144 |
try { |
145 |
runDirectorApp("3.1", metadataRepo.toURL(), artifactRepo.toURL(), destinationRepo.toURL(), installIU); |
146 |
} catch (MalformedURLException e) { |
147 |
fail("3.2", e); |
148 |
} catch (CoreException e) { |
149 |
//fall through |
150 |
} catch (Exception e) { |
151 |
fail("3.3", e); |
152 |
} |
153 |
|
154 |
//ensures that repository has not been mistakenly created |
155 |
assertTrue("3.4", !artifactRepo.exists()); |
156 |
assertTrue("3.5", metadataRepo.exists()); |
157 |
|
158 |
//Cleanup: delete the folders |
159 |
delete(artifactRepo); |
160 |
delete(destinationRepo); |
161 |
} |
162 |
} |