Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: cb2f99a9225679e9f2f5f324de8afd37afd1933f (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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
/*******************************************************************************
 * Copyright (c) 2007, 2008 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.engine;

import java.io.*;
import java.util.*;
import java.util.Map.Entry;
import javax.xml.parsers.ParserConfigurationException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper;
import org.eclipse.equinox.internal.p2.engine.*;
import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException;
import org.eclipse.equinox.internal.provisional.p2.core.Version;
import org.eclipse.equinox.internal.provisional.p2.engine.*;
import org.eclipse.equinox.internal.provisional.p2.metadata.IInstallableUnit;
import org.eclipse.equinox.internal.provisional.p2.metadata.query.InstallableUnitQuery;
import org.eclipse.equinox.internal.provisional.p2.query.Collector;
import org.eclipse.equinox.internal.provisional.p2.query.Query;
import org.eclipse.equinox.p2.tests.AbstractProvisioningTest;
import org.eclipse.equinox.p2.tests.TestActivator;
import org.osgi.framework.BundleContext;
import org.xml.sax.*;

/**
 * Simple test of the engine API.
 */
public class ProfileTest extends AbstractProvisioningTest {

	private static final String PROFILE_NAME = "ProfileTest";

	public ProfileTest(String name) {
		super(name);
	}

	public ProfileTest() {
		super("");
	}

	public void testNullProfile() {
		try {
			createProfile(null);
		} catch (IllegalArgumentException expected) {
			return;
		}
		fail();
	}

	public void testEmptyProfile() {
		try {
			createProfile("");
		} catch (IllegalArgumentException expected) {
			return;
		}
		fail();
	}

	public void testAddRemoveProperty() throws ProvisionException {
		IProfileRegistry registry = (IProfileRegistry) ServiceHelper.getService(TestActivator.getContext(), IProfileRegistry.class.getName());
		assertNull(registry.getProfile(PROFILE_NAME));
		Properties properties = new Properties();
		properties.put("test", "test");
		Profile profile = (Profile) registry.addProfile(PROFILE_NAME, properties);
		assertTrue(profile.getProperties().containsKey("test"));
		assertEquals("test", profile.getProperty("test"));
		profile.removeProperty("test");
		assertNull(profile.getProperty("test"));
		profile.addProperties(properties);
		assertEquals("test", profile.getProperty("test"));
		profile.setProperty("test", "newvalue");
		assertEquals("newvalue", profile.getProperty("test"));
		registry.removeProfile(PROFILE_NAME);
		assertNull(registry.getProfile(PROFILE_NAME));
	}

	public void testAddRemoveIU() throws ProvisionException {
		IProfileRegistry registry = (IProfileRegistry) ServiceHelper.getService(TestActivator.getContext(), IProfileRegistry.class.getName());
		assertNull(registry.getProfile(PROFILE_NAME));
		Profile profile = (Profile) registry.addProfile(PROFILE_NAME);
		assertTrue(profile.query(InstallableUnitQuery.ANY, new Collector(), null).isEmpty());
		profile.addInstallableUnit(createIU("test"));
		assertEquals(1, profile.query(InstallableUnitQuery.ANY, new Collector(), null).size());
		profile.removeInstallableUnit(createIU("test"));
		assertTrue(profile.query(InstallableUnitQuery.ANY, new Collector(), null).isEmpty());
		registry.removeProfile(PROFILE_NAME);
		assertNull(registry.getProfile(PROFILE_NAME));
	}

	public void testAddIUTwice() throws ProvisionException {
		IProfileRegistry registry = (IProfileRegistry) ServiceHelper.getService(TestActivator.getContext(), IProfileRegistry.class.getName());
		assertNull(registry.getProfile(PROFILE_NAME));
		Profile profile = (Profile) registry.addProfile(PROFILE_NAME);
		assertTrue(profile.query(InstallableUnitQuery.ANY, new Collector(), null).isEmpty());
		profile.addInstallableUnit(createIU("test"));
		assertEquals(1, profile.query(InstallableUnitQuery.ANY, new Collector(), null).size());
		profile.addInstallableUnit(createIU("test"));
		assertEquals(1, profile.query(InstallableUnitQuery.ANY, new Collector(), null).size());
		registry.removeProfile(PROFILE_NAME);
		assertNull(registry.getProfile(PROFILE_NAME));
	}

	public void testAddRemoveIUProperty() throws ProvisionException {
		IProfileRegistry registry = (IProfileRegistry) ServiceHelper.getService(TestActivator.getContext(), IProfileRegistry.class.getName());
		assertNull(registry.getProfile(PROFILE_NAME));
		Profile profile = (Profile) registry.addProfile(PROFILE_NAME);
		assertTrue(profile.query(InstallableUnitQuery.ANY, new Collector(), null).isEmpty());
		profile.addInstallableUnit(createIU("test"));
		assertNull(profile.getInstallableUnitProperty(createIU("test"), "test"));
		assertNull(profile.removeInstallableUnitProperty(createIU("test"), "test"));
		Properties iuProperties = new Properties();
		iuProperties.put("test", "test");
		profile.addInstallableUnitProperties(createIU("test"), iuProperties);
		assertEquals("test", profile.getInstallableUnitProperty(createIU("test"), "test"));
		profile.removeInstallableUnitProperty(createIU("test"), "test");
		assertNull(profile.getInstallableUnitProperty(createIU("test"), "test"));
		assertEquals(1, profile.query(InstallableUnitQuery.ANY, new Collector(), null).size());
		registry.removeProfile(PROFILE_NAME);
		assertNull(registry.getProfile(PROFILE_NAME));
	}

	public void testAvailable() throws ProvisionException {
		IProfileRegistry registry = (IProfileRegistry) ServiceHelper.getService(TestActivator.getContext(), IProfileRegistry.class.getName());
		assertNull(registry.getProfile(PROFILE_NAME));
		Profile profile = (Profile) registry.addProfile(PROFILE_NAME);
		assertTrue(profile.available(InstallableUnitQuery.ANY, new Collector(), null).isEmpty());
		profile.addInstallableUnit(createIU("test"));
		assertEquals(1, profile.available(InstallableUnitQuery.ANY, new Collector(), null).size());
		profile.setSurrogateProfileHandler(new ISurrogateProfileHandler() {
			public IProfile createProfile(String id) {
				return null;
			}

			public boolean isSurrogate(IProfile profile) {
				return false;
			}

			public Collector queryProfile(IProfile profile, Query query, Collector collector, IProgressMonitor monitor) {
				return collector;
			}

			public boolean updateProfile(IProfile selfProfile) {
				return false;
			}
		});
		assertTrue(profile.available(InstallableUnitQuery.ANY, new Collector(), null).isEmpty());
		assertTrue(profile.snapshot().available(InstallableUnitQuery.ANY, new Collector(), null).isEmpty());
		registry.removeProfile(PROFILE_NAME);
		assertNull(registry.getProfile(PROFILE_NAME));
	}

	public void testNestedProfileStructure() {
		Properties properties = new Properties();
		properties.put("test", "test");
		IProfile parent = createProfile("parent", null, properties);
		IProfile child = createProfile("child", "parent");
		parent = getProfile("parent");
		assertTrue(parent.hasSubProfiles());
		assertFalse(child.hasSubProfiles());
		assertNotNull(parent.getLocalProperty("test"));
		assertNotNull(child.getProperty("test"));
		assertNotNull(child.getProperties().get("test"));
		assertNull(child.getLocalProperty("test"));
		assertNull(child.getLocalProperties().get("test"));

		assertTrue("Parentless profile should be a root.", parent.isRootProfile());
		assertFalse("Child profile should not be a root.", child.isRootProfile());
		assertTrue("Parent should be parent of child", child.getParentProfile().getProfileId().equals(parent.getProfileId()));
		assertTrue("Parent should have one child.", parent.getSubProfileIds().length == 1);
		assertTrue("Child should have no children.", child.getSubProfileIds().length == 0);

		IProfile grandchild = createProfile("grand", "child");
		child = getProfile("child");
		assertFalse("Grandchild profile should not be a root.", grandchild.isRootProfile());
		assertTrue("Parent should have one child.", parent.getSubProfileIds().length == 1);
		assertTrue("Child should have one child.", child.getSubProfileIds().length == 1);
		assertTrue("Grandparent of grandchild should be parent of child.", grandchild.getParentProfile().getParentProfile().getProfileId().equals(parent.getProfileId()));
	}

	/*	The test profile has the following structure and properties where
	 *  	id{x,y}  indicates a profile with id "id" and properties defined
	 *				 with keys "x" and "y"
	 *
	 *                                    grandchild00{foo}
	 *                                   /
	 *                                  /
	 *                      child0{foo} | --- grandchild01{}
	 *                     /             \
	 *					  /               \
	 *                   /                 grandchild01{bar}
	 *	parent{foo,bar} |				   
	 *                   \            grandchild10{foo}
	 *                    \          /
	 *                     child1{} |
	 *								 \
	 *                                grandchild11{}
	 *
	 */
	private static String parentId = "parent";
	private static String child0Id = "child0";
	private static String grandchild00Id = "grand00";
	private static String grandchild01Id = "grand01";
	private static String grandchild02Id = "grand02";
	private static String child1Id = "child1";
	private static String grandchild10Id = "grand10";
	private static String grandchild11Id = "grand11";

	private static String key = "org.eclipse.p2.foo";
	private static String parentValue = "parent";
	private static String child0Value = "child0";
	private static String grandchild00Value = "grandchild00";
	private static String grandchild02Value = "grandchild02";
	private static String grandchild10Value = "grandchild10";
	private static String otherKey = "org.eclipse.p2.bar";
	private static String otherValue = "other";

	// Create the profiles and test get after set
	// for associated properties.
	private IProfile[] createTestProfiles() {

		Map properties = new HashMap();

		properties.put(key, parentValue);
		properties.put(otherKey, otherValue);
		IProfile parent = createProfile(parentId, null, properties);
		properties.clear();
		assertTrue(parentValue.equals(parent.getProperty(key)));
		assertTrue(otherValue.equals(parent.getProperty(otherKey)));

		properties.put(key, child0Value);
		IProfile child0 = createProfile(child0Id, parentId, properties);
		properties.clear();
		assertTrue(child0Value.equals(child0.getProperty(key)));

		IProfile child1 = createProfile(child1Id, parentId, properties);
		// no value in child1

		properties.put(key, grandchild00Value);
		IProfile grandchild00 = createProfile(grandchild00Id, child0Id, properties);
		properties.clear();
		assertTrue(grandchild00Value.equals(grandchild00.getProperty(key)));

		IProfile grandchild01 = createProfile(grandchild01Id, child0Id);
		// no value in grandchild01

		properties.put(otherKey, grandchild02Value);
		IProfile grandchild02 = createProfile(grandchild02Id, child0Id, properties);
		properties.clear();
		assertTrue(grandchild02Value.equals(grandchild02.getProperty(otherKey)));

		properties.put(key, grandchild10Value);
		IProfile grandchild10 = createProfile(grandchild10Id, child1Id, properties);
		properties.clear();
		assertTrue(grandchild10Value.equals(grandchild10.getProperty(key)));

		IProfile grandchild11 = createProfile(grandchild11Id, child1Id);
		// no value in grandchild11

		parent = getProfile(parentId);
		child0 = getProfile(child0Id);
		child1 = getProfile(child1Id);
		grandchild00 = getProfile(grandchild00Id);
		grandchild01 = getProfile(grandchild01Id);
		grandchild02 = getProfile(grandchild02Id);
		grandchild10 = getProfile(grandchild10Id);
		grandchild11 = getProfile(grandchild11Id);

		IProfile[] profiles = {parent, child0, child1, grandchild00, grandchild01, grandchild02, grandchild10, grandchild11};
		return profiles;
	}

	public void testNestedProfileProperties() {
		validateProfiles(createTestProfiles());
	}

	public void validateProfiles(IProfile[] profiles) {
		IProfile parent = profiles[0];
		IProfile child0 = profiles[1];
		IProfile child1 = profiles[2];
		IProfile grandchild00 = profiles[3];
		IProfile grandchild01 = profiles[4];
		IProfile grandchild02 = profiles[5];
		IProfile grandchild10 = profiles[6];
		IProfile grandchild11 = profiles[7];

		assertTrue(parentId.equals(parent.getProfileId()));
		assertTrue("Profile should have 3 local properties", parent.getLocalProperties().size() == 2);
		assertTrue(parentValue.equals(parent.getProperty(key)));
		assertTrue(otherValue.equals(parent.getProperty(otherKey)));
		assertTrue("Parent should have 2 children.", parent.getSubProfileIds().length == 2);

		assertTrue(child0Id.equals(child0.getProfileId()));
		assertTrue("First Child should have 1 local properties.", child0.getLocalProperties().size() == 1);
		assertTrue(child0Value.equals(child0.getProperty(key)));
		assertTrue(otherValue.equals(child0.getProperty(otherKey)));
		assertTrue("First Child should have 3 children.", child0.getSubProfileIds().length == 3);

		assertTrue(child1Id.equals(child1.getProfileId()));
		assertTrue("Second Child should have 0 local properties.", child1.getLocalProperties().size() == 0);
		assertTrue(parentValue.equals(child1.getProperty(key)));
		assertTrue(otherValue.equals(child1.getProperty(otherKey)));
		assertTrue("Second Child should have 2 children.", child1.getSubProfileIds().length == 2);

		assertTrue(grandchild00Id.equals(grandchild00.getProfileId()));
		assertTrue("First Grandchild of first Child should have 1 property.", grandchild00.getLocalProperties().size() == 1);
		assertTrue(grandchild00Value.equals(grandchild00.getProperty(key)));
		assertTrue(otherValue.equals(grandchild00.getProperty(otherKey)));

		assertTrue(grandchild01Id.equals(grandchild01.getProfileId()));
		assertTrue("Second Grandchild of first Child should have 0 properties.", grandchild01.getLocalProperties().size() == 0);
		assertTrue(child0Value.equals(grandchild01.getProperty(key)));
		assertTrue(otherValue.equals(grandchild01.getProperty(otherKey)));

		assertTrue(grandchild02Id.equals(grandchild02.getProfileId()));
		assertTrue("Third Grandchild of first Child should have 1 property.", grandchild02.getLocalProperties().size() == 1);
		assertTrue(child0Value.equals(grandchild02.getProperty(key)));
		assertTrue(grandchild02Value.equals(grandchild02.getProperty(otherKey)));

		assertTrue(grandchild10Id.equals(grandchild10.getProfileId()));
		assertTrue("First Grandchild of second Child should have 1 property.", grandchild10.getLocalProperties().size() == 1);
		assertTrue(grandchild10Value.equals(grandchild10.getProperty(key)));
		assertTrue(otherValue.equals(grandchild10.getProperty(otherKey)));

		assertTrue(grandchild11Id.equals(grandchild11.getProfileId()));
		assertTrue("Second Grandchild of second Child should have 0 properties.", grandchild11.getLocalProperties().size() == 0);
		assertTrue(parentValue.equals(grandchild11.getProperty(key)));
		assertTrue(otherValue.equals(grandchild11.getProperty(otherKey)));
	}

	private static String PROFILE_TEST_TARGET = "profileTest";
	private static Version PROFILE_TEST_VERSION = new Version("0.0.1");

	private static String PROFILE_TEST_ELEMENT = "test";
	public static final String PROFILES_ELEMENT = "profiles"; //$NON-NLS-1$

	class ProfileStringWriter extends ProfileWriter {

		public ProfileStringWriter(ByteArrayOutputStream stream) throws IOException {
			super(stream, new ProcessingInstruction[] {ProcessingInstruction.makeTargetVersionInstruction(PROFILE_TEST_TARGET, PROFILE_TEST_VERSION)});
		}

		public void writeTest(IProfile[] profiles) {
			start(PROFILE_TEST_ELEMENT);
			writeProfiles(profiles);
			end(PROFILE_TEST_ELEMENT);
			flush();
		}

		public void writeProfiles(IProfile[] profiles) {
			if (profiles.length > 0) {
				start(PROFILES_ELEMENT);
				attribute(COLLECTION_SIZE_ATTRIBUTE, profiles.length);
				for (int i = 0; i < profiles.length; i++) {
					writeProfile(profiles[i]);
				}
				end(PROFILES_ELEMENT);
			}
		}
	}

	class ProfileStringParser extends ProfileParser {

		private IProfile[] profiles = null;

		public ProfileStringParser(BundleContext context, String bundleId) {
			super(context, bundleId);
		}

		public void parse(String profileString) throws IOException {
			this.status = null;
			try {
				getParser();
				TestHandler testHandler = new TestHandler();
				xmlReader.setContentHandler(new ProfileDocHandler(PROFILE_TEST_ELEMENT, testHandler));
				xmlReader.parse(new InputSource(new StringReader(profileString)));
				if (isValidXML()) {
					profiles = testHandler.profiles;
				}
			} catch (SAXException e) {
				throw new IOException(e.getMessage());
			} catch (ParserConfigurationException e) {
				fail();
			}
		}

		private final class ProfileDocHandler extends DocHandler {

			public ProfileDocHandler(String rootName, RootHandler rootHandler) {
				super(rootName, rootHandler);
			}

			public void processingInstruction(String target, String data) throws SAXException {
				if (PROFILE_TEST_TARGET.equals(target)) {
					Version profileTestVersion = extractPIVersion(target, data);
					if (!PROFILE_TEST_VERSION.equals(profileTestVersion)) {
						throw new SAXException("Bad profile test version.");
					}
				}
			}
		}

		private final class TestHandler extends RootHandler {

			private ProfilesHandler profilesHandler;
			IProfile[] profiles;

			protected void handleRootAttributes(Attributes attributes) {
			}

			public void startElement(String name, Attributes attributes) throws SAXException {
				if (PROFILES_ELEMENT.equals(name)) {
					if (profilesHandler == null) {
						profilesHandler = new ProfilesHandler(this, attributes);
					} else {
						duplicateElement(this, name, attributes);
					}
				} else {
					invalidElement(name, attributes);
				}
			}

			protected void finished() {
				if (isValidXML()) {
					if (profilesHandler != null) {
						profiles = profilesHandler.getProfiles();
					}
				}
			}

		}

		protected class ProfilesHandler extends AbstractHandler {

			private final Map profileHandlers;

			public ProfilesHandler(AbstractHandler parentHandler, Attributes attributes) {
				super(parentHandler, PROFILES_ELEMENT);
				String size = parseOptionalAttribute(attributes, COLLECTION_SIZE_ATTRIBUTE);
				profileHandlers = (size != null ? new HashMap(new Integer(size).intValue()) : new HashMap(4));
			}

			public IProfile[] getProfiles() {
				if (profileHandlers.isEmpty())
					return new IProfile[0];

				Map profileMap = new LinkedHashMap();
				for (Iterator it = profileHandlers.keySet().iterator(); it.hasNext();) {
					String profileId = (String) it.next();
					addProfile(profileId, profileMap);
				}

				return (IProfile[]) profileMap.values().toArray(new IProfile[profileMap.size()]);
			}

			private void addProfile(String profileId, Map profileMap) {
				if (profileMap.containsKey(profileId))
					return;

				ProfileHandler profileHandler = (ProfileHandler) profileHandlers.get(profileId);
				Profile parentProfile = null;

				String parentId = profileHandler.getParentId();
				if (parentId != null) {
					addProfile(parentId, profileMap);
					parentProfile = (Profile) profileMap.get(parentId);
				}

				Profile profile = new Profile(profileId, parentProfile, profileHandler.getProperties());
				profile.setTimestamp(profileHandler.getTimestamp());
				IInstallableUnit[] ius = profileHandler.getInstallableUnits();
				if (ius != null) {
					for (int i = 0; i < ius.length; i++) {
						IInstallableUnit iu = ius[i];
						profile.addInstallableUnit(iu);
						Map iuProperties = profileHandler.getIUProperties(iu);
						if (iuProperties != null) {
							for (Iterator it = iuProperties.entrySet().iterator(); it.hasNext();) {
								Entry entry = (Entry) it.next();
								String key = (String) entry.getKey();
								String value = (String) entry.getValue();
								profile.setInstallableUnitProperty(iu, key, value);
							}
						}
					}
				}
				profileMap.put(profileId, profile);
			}

			public void startElement(String name, Attributes attributes) {
				if (name.equals(PROFILE_ELEMENT)) {
					new ProfilesProfileHandler(this, attributes, profileHandlers);
				} else {
					invalidElement(name, attributes);
				}
			}
		}

		public class ProfilesProfileHandler extends ProfileHandler {
			private final Map profileHandlers;

			public ProfilesProfileHandler(ProfilesHandler profilesHandler, Attributes attributes, Map profileHandlers) {
				this.profileHandlers = profileHandlers;
				this.parentHandler = profilesHandler;
				xmlReader.setContentHandler(this);
				handleRootAttributes(attributes);
			}

			protected void finished() {
				if (isValidXML()) {
					profileHandlers.put(getProfileId(), this);
				}
			}
		}

		protected String getErrorMessage() {
			return "Error parsing profile string";
		}

		protected Object getRootObject() {
			Map result = new HashMap();
			for (int i = 0; i < profiles.length; i++) {
				result.put(profiles[i].getProfileId(), profiles[i]);
			}
			return result;
		}
	}

	public void testProfilePersistence() throws IOException {
		IProfile[] testProfiles = createTestProfiles();
		ByteArrayOutputStream output0 = new ByteArrayOutputStream(1492);
		ProfileStringWriter writer0 = new ProfileStringWriter(output0);
		writer0.writeTest(testProfiles);
		String profileText0 = output0.toString();
		output0.close();

		ProfileStringParser parser = new ProfileStringParser(TestActivator.context, TestActivator.PI_PROV_TESTS);
		parser.parse(profileText0);
		assertTrue("Error parsing test profile: " + parser.getStatus().getMessage(), parser.getStatus().isOK());
		Map profileMap = (Map) parser.getRootObject();
		IProfile parent = (IProfile) profileMap.get(parentId);
		IProfile child0 = (IProfile) profileMap.get(child0Id);
		IProfile child1 = (IProfile) profileMap.get(child1Id);
		IProfile grandchild00 = (IProfile) profileMap.get(grandchild00Id);
		IProfile grandchild01 = (IProfile) profileMap.get(grandchild01Id);
		IProfile grandchild02 = (IProfile) profileMap.get(grandchild02Id);
		IProfile grandchild10 = (IProfile) profileMap.get(grandchild10Id);
		IProfile grandchild11 = (IProfile) profileMap.get(grandchild11Id);
		IProfile[] profiles = {parent, child0, child1, grandchild00, grandchild01, grandchild02, grandchild10, grandchild11};
		validateProfiles(profiles);
		ByteArrayOutputStream output1 = new ByteArrayOutputStream(1492);
		ProfileStringWriter writer = new ProfileStringWriter(output1);

		writer.writeTest(profiles);
		String profileText1 = output1.toString();
		output1.close();
		assertTrue("Profile write after read after write produced different XML", profileText1.equals(profileText0));
	}
}

Back to the top