1 /*******************************************************************************
2  * Copyright (c) 2009, 2016 IBM Corporation and others.
3  *
4  * This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License 2.0
6  * which accompanies this distribution, and is available at
7  * https://www.eclipse.org/legal/epl-2.0/
8  *
9  * SPDX-License-Identifier: EPL-2.0
10  *
11  * Contributors:
12  *     IBM Corporation - initial API and implementation
13  *******************************************************************************/
14 
15 package org.eclipse.ua.tests.help.other;
16 
17 import static org.junit.Assert.assertEquals;
18 
19 import org.eclipse.core.runtime.IProduct;
20 import org.eclipse.core.runtime.Platform;
21 import org.eclipse.help.internal.util.ProductPreferences;
22 import org.junit.Test;
23 import org.osgi.framework.Bundle;
24 
25 public class PathResolutionTest {
26 	@Test
testResolveNull()27 	public void testResolveNull() {
28 		assertEquals(null, ProductPreferences.resolveSpecialIdentifiers(null));
29 	}
30 
31 	@Test
testResolveSimplePath()32 	public void testResolveSimplePath() {
33 		assertEquals("/a.b.c/toc.xml", ProductPreferences.resolveSpecialIdentifiers("/a.b.c/toc.xml"));
34 	}
35 
36 	@Test
testResolvePluginsRoot()37 	public void testResolvePluginsRoot() {
38 		assertEquals("/a.b.c/toc.xml", ProductPreferences.resolveSpecialIdentifiers("PLUGINS_ROOT/a.b.c/toc.xml"));
39 	}
40 
41 	@Test
testResolveSlashPluginsRoot()42 	public void testResolveSlashPluginsRoot() {
43 		assertEquals("/a.b.c/toc.xml", ProductPreferences.resolveSpecialIdentifiers("/PLUGINS_ROOT/a.b.c/toc.xml"));
44 	}
45 
46 	@Test
testResolveEmbeddedPluginsRoot()47 	public void testResolveEmbeddedPluginsRoot() {
48 		assertEquals("/a.b.c/toc.xml", ProductPreferences.resolveSpecialIdentifiers("../PLUGINS_ROOT/a.b.c/toc.xml"));
49 	}
50 
51 	@Test
testResolvePluginsRootProductPlugin()52 	public void testResolvePluginsRootProductPlugin() {
53 		IProduct product = Platform.getProduct();
54 		if (product != null) {
55 			Bundle productBundle = product.getDefiningBundle();
56 			if (productBundle != null) {
57 				String bundleName = productBundle.getSymbolicName();
58 				assertEquals('/' + bundleName + "/toc.xml", ProductPreferences.resolveSpecialIdentifiers("PLUGINS_ROOT/PRODUCT_PLUGIN/toc.xml"));
59 			}
60 		}
61 	}
62 
63 	@Test
testResolveProductPlugin()64 	public void testResolveProductPlugin() {
65 		IProduct product = Platform.getProduct();
66 		if (product != null) {
67 			Bundle productBundle = product.getDefiningBundle();
68 			if (productBundle != null) {
69 				String bundleName = productBundle.getSymbolicName();
70 				assertEquals('/' + bundleName + "/toc.xml", ProductPreferences.resolveSpecialIdentifiers("PRODUCT_PLUGIN/toc.xml"));
71 			}
72 		}
73 	}
74 
75 	@Test
testResolveSlashProductPlugin()76 	public void testResolveSlashProductPlugin() {
77 		IProduct product = Platform.getProduct();
78 		if (product != null) {
79 			Bundle productBundle = product.getDefiningBundle();
80 			if (productBundle != null) {
81 				String bundleName = productBundle.getSymbolicName();
82 				assertEquals('/' + bundleName + "/toc.xml", ProductPreferences.resolveSpecialIdentifiers("/PRODUCT_PLUGIN/toc.xml"));
83 			}
84 		}
85 	}
86 
87 
88 }
89