Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: f4631fc83308a6016762a43489fd6ce30b8da37c (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
/*******************************************************************************
 * Copyright (c) 2008, 2009 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.simpleconfigurator.manipulator;

import java.net.URI;
import java.net.URISyntaxException;
import org.eclipse.equinox.internal.simpleconfigurator.manipulator.SimpleConfiguratorManipulatorUtils;
import org.eclipse.equinox.internal.simpleconfigurator.utils.BundleInfo;
import org.eclipse.equinox.internal.simpleconfigurator.utils.SimpleConfiguratorUtils;
import org.eclipse.equinox.p2.tests.AbstractProvisioningTest;

public class SimpleConfiguratorManipulatorUtilsTest extends AbstractProvisioningTest {

	public void testWriteBundleInfoLine() throws URISyntaxException {
		String expectedLine = "javax.servlet,2.4.0.v200806031604,plugins/javax.servlet_2.4.0.v200806031604.jar,4,false";
		BundleInfo bundleInfo = new BundleInfo("javax.servlet", "2.4.0.v200806031604", new URI("plugins/javax.servlet_2.4.0.v200806031604.jar"), 4, false);
		String line = SimpleConfiguratorManipulatorUtils.createBundleInfoLine(bundleInfo, false);
		assertEquals(expectedLine, line);
		assertEquals(bundleInfo, SimpleConfiguratorUtils.parseBundleInfoLine(line, null));
	}

	public void testWriteBundleInfoLineWithComma() throws URISyntaxException {
		String expectedLine = "javax.servlet,2.4.0.v200806031604,plugin%2Cs/javax.servlet_2.4.0.v200806031604.jar,4,false";
		BundleInfo bundleInfo = new BundleInfo("javax.servlet", "2.4.0.v200806031604", new URI("plugin,s/javax.servlet_2.4.0.v200806031604.jar"), 4, false);
		String line = SimpleConfiguratorManipulatorUtils.createBundleInfoLine(bundleInfo, false);
		assertEquals(expectedLine, line);
		assertEquals(bundleInfo, SimpleConfiguratorUtils.parseBundleInfoLine(line, null));
	}

	public void testWriteBundleInfoLineWithSpace() throws URISyntaxException {
		String expectedLine = "javax.servlet,2.4.0.v200806031604,plugin%20s/javax.servlet_2.4.0.v200806031604.jar,4,false";
		BundleInfo bundleInfo = new BundleInfo("javax.servlet", "2.4.0.v200806031604", new URI("plugin%20s/javax.servlet_2.4.0.v200806031604.jar"), 4, false);
		String line = SimpleConfiguratorManipulatorUtils.createBundleInfoLine(bundleInfo, false);
		assertEquals(expectedLine, line);
		assertEquals(bundleInfo, SimpleConfiguratorUtils.parseBundleInfoLine(line, null));
	}

	public void testWriteBundleInfoLineWithAtSymbol() throws URISyntaxException {
		String expectedLine = "javax.servlet,2.4.0.v200806031604,plugin@s/javax.servlet_2.4.0.v200806031604.jar,4,false";
		BundleInfo bundleInfo = new BundleInfo("javax.servlet", "2.4.0.v200806031604", new URI("plugin@s/javax.servlet_2.4.0.v200806031604.jar"), 4, false);
		String line = SimpleConfiguratorManipulatorUtils.createBundleInfoLine(bundleInfo, false);
		assertEquals(expectedLine, line);
		assertEquals(bundleInfo, SimpleConfiguratorUtils.parseBundleInfoLine(line, null));
	}

	public void testWriteVersionLine() {
		String expectedVersionPrefix = "#version=";
		String versionLine = SimpleConfiguratorManipulatorUtils.createVersionLine();
		assertTrue(versionLine.startsWith(expectedVersionPrefix));

		SimpleConfiguratorUtils.parseCommentLine(versionLine);
		try {
			SimpleConfiguratorUtils.parseCommentLine(expectedVersionPrefix + "999");
		} catch (IllegalArgumentException e) {
			return;
		}
		fail("improper version error not caught");
	}
}

Back to the top