|
| 1 | +/* |
| 2 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
| 3 | + * |
| 4 | + * Copyright (c) 2015 Oracle and/or its affiliates. All rights reserved. |
| 5 | + * |
| 6 | + * The contents of this file are subject to the terms of either the GNU |
| 7 | + * General Public License Version 2 only ("GPL") or the Common Development |
| 8 | + * and Distribution License("CDDL") (collectively, the "License"). You |
| 9 | + * may not use this file except in compliance with the License. You can |
| 10 | + * obtain a copy of the License at |
| 11 | + * http://glassfish.java.net/public/CDDL+GPL_1_1.html |
| 12 | + * or packager/legal/LICENSE.txt. See the License for the specific |
| 13 | + * language governing permissions and limitations under the License. |
| 14 | + * |
| 15 | + * When distributing the software, include this License Header Notice in each |
| 16 | + * file and include the License file at packager/legal/LICENSE.txt. |
| 17 | + * |
| 18 | + * GPL Classpath Exception: |
| 19 | + * Oracle designates this particular file as subject to the "Classpath" |
| 20 | + * exception as provided by Oracle in the GPL Version 2 section of the License |
| 21 | + * file that accompanied this code. |
| 22 | + * |
| 23 | + * Modifications: |
| 24 | + * If applicable, add the following below the License Header, with the fields |
| 25 | + * enclosed by brackets [] replaced by your own identifying information: |
| 26 | + * "Portions Copyright [year] [name of copyright owner]" |
| 27 | + * |
| 28 | + * Contributor(s): |
| 29 | + * If you wish your version of this file to be governed by only the CDDL or |
| 30 | + * only the GPL Version 2, indicate your decision by adding "[Contributor] |
| 31 | + * elects to include this software in this distribution under the [CDDL or GPL |
| 32 | + * Version 2] license." If you don't indicate a single choice of license, a |
| 33 | + * recipient has the option to distribute your version of this file under |
| 34 | + * either the CDDL, the GPL Version 2 or to extend the choice of license to |
| 35 | + * its licensees as provided above. However, if you add GPL Version 2 code |
| 36 | + * and therefore, elected the GPL Version 2 license, then the option applies |
| 37 | + * only if the new code is made subject to such option by the copyright |
| 38 | + * holder. |
| 39 | + */ |
| 40 | +package org.glassfish.jersey.internal.util; |
| 41 | + |
| 42 | +import org.glassfish.jersey.internal.OsgiRegistry; |
| 43 | + |
| 44 | +import org.junit.Assert; |
| 45 | +import org.junit.Test; |
| 46 | + |
| 47 | +/** |
| 48 | + * Utility class {@ling OsgiRegistry} tests. |
| 49 | + * |
| 50 | + * @author Stepan Vavra (stepan.vavra at oracle.com) |
| 51 | + */ |
| 52 | +public class OsgiRegistryTest { |
| 53 | + |
| 54 | + @Test |
| 55 | + public void testWebInfClassesBundleEntryPathTranslation() { |
| 56 | + String className = OsgiRegistry |
| 57 | + .bundleEntryPathToClassName("org/glassfish/jersey", "/WEB-INF/classes/org/glassfish/jersey/Test.class"); |
| 58 | + Assert.assertEquals("org.glassfish.jersey.Test", className); |
| 59 | + } |
| 60 | + |
| 61 | + @Test |
| 62 | + public void testWebInfClassesBundleEntryPathTranslationPackageTrailingSlash() { |
| 63 | + String className = OsgiRegistry |
| 64 | + .bundleEntryPathToClassName("org/glassfish/jersey/", "/WEB-INF/classes/org/glassfish/jersey/Test.class"); |
| 65 | + Assert.assertEquals("org.glassfish.jersey.Test", className); |
| 66 | + } |
| 67 | + |
| 68 | + @Test |
| 69 | + public void testWebInfClassesBundleEntryPathTranslationPackageLeadingSlash() { |
| 70 | + String className = OsgiRegistry |
| 71 | + .bundleEntryPathToClassName("/org/glassfish/jersey", "/WEB-INF/classes/org/glassfish/jersey/Test.class"); |
| 72 | + Assert.assertEquals("org.glassfish.jersey.Test", className); |
| 73 | + } |
| 74 | + |
| 75 | + @Test |
| 76 | + public void testWebInfClassesBundleEntryPathTranslationBundleNoLeadingSlash() { |
| 77 | + String className = OsgiRegistry |
| 78 | + .bundleEntryPathToClassName("/org/glassfish/jersey", "WEB-INF/classes/org/glassfish/jersey/Test.class"); |
| 79 | + Assert.assertEquals("org.glassfish.jersey.Test", className); |
| 80 | + } |
| 81 | + |
| 82 | + @Test |
| 83 | + public void testOsgiInfClassesBundleEntryPathTranslation() { |
| 84 | + String className = OsgiRegistry |
| 85 | + .bundleEntryPathToClassName("/org/glassfish/jersey", "OSGI-INF/directory/org/glassfish/jersey/Test.class"); |
| 86 | + Assert.assertEquals("org.glassfish.jersey.Test", className); |
| 87 | + } |
| 88 | + |
| 89 | + @Test |
| 90 | + public void testBundleEntryPathTranslation() { |
| 91 | + String className = OsgiRegistry.bundleEntryPathToClassName("/org/glassfish/jersey", "/org/glassfish/jersey/Test.class"); |
| 92 | + Assert.assertEquals("org.glassfish.jersey.Test", className); |
| 93 | + } |
| 94 | + |
| 95 | + @Test |
| 96 | + public void testBundleEntryPathTranslationBundleNoLeadingSlash() { |
| 97 | + String className = OsgiRegistry.bundleEntryPathToClassName("/org/glassfish/jersey", "org/glassfish/jersey/Test.class"); |
| 98 | + Assert.assertEquals("org.glassfish.jersey.Test", className); |
| 99 | + } |
| 100 | + |
| 101 | + @Test |
| 102 | + public void testBundleEntryPathTranslationNotMatching() { |
| 103 | + String className = OsgiRegistry.bundleEntryPathToClassName("/com/oracle", "org/glassfish/jersey/Test.class"); |
| 104 | + Assert.assertEquals("com.oracle.Test", className); |
| 105 | + } |
| 106 | + |
| 107 | + @Test |
| 108 | + public void testWebInfClassesBundleEntryPathTranslationNotMatching() { |
| 109 | + String className = OsgiRegistry |
| 110 | + .bundleEntryPathToClassName("/com/oracle/", "/WEB-INF/classes/org/glassfish/jersey/Test.class"); |
| 111 | + Assert.assertEquals("com.oracle.Test", className); |
| 112 | + } |
| 113 | + |
| 114 | + @Test |
| 115 | + public void testWebInfClassesBundleEntryPathTranslationNotMatching2() { |
| 116 | + String className = OsgiRegistry.bundleEntryPathToClassName("com/oracle", "/org/glassfish/jersey/Test.class"); |
| 117 | + Assert.assertEquals("com.oracle.Test", className); |
| 118 | + } |
| 119 | + |
| 120 | + @Test |
| 121 | + public void testRootBundleEntryPathTranslation() { |
| 122 | + String className = OsgiRegistry.bundleEntryPathToClassName("/", "/org/glassfish/jersey/Test.class"); |
| 123 | + Assert.assertEquals("org.glassfish.jersey.Test", className); |
| 124 | + } |
| 125 | + |
| 126 | + @Test |
| 127 | + public void testRootBundleEntryPathTranslationNoLeadingSlash() { |
| 128 | + String className = OsgiRegistry.bundleEntryPathToClassName("/", "org/glassfish/jersey/Test.class"); |
| 129 | + Assert.assertEquals("org.glassfish.jersey.Test", className); |
| 130 | + } |
| 131 | + |
| 132 | + @Test |
| 133 | + public void testRootWebInfClassesBundleEntryPathTranslationNoLeadingSlash() { |
| 134 | + String className = OsgiRegistry.bundleEntryPathToClassName("/", "/WEB-INF/classes/org/glassfish/jersey/Test.class"); |
| 135 | + Assert.assertEquals("org.glassfish.jersey.Test", className); |
| 136 | + } |
| 137 | + |
| 138 | + @Test |
| 139 | + public void testRootWebInfClassesBundleEntryPathEsTranslation() { |
| 140 | + String className = OsgiRegistry.bundleEntryPathToClassName("es", "/WEB-INF/classes/es/a/Test.class"); |
| 141 | + Assert.assertEquals("es.a.Test", className); |
| 142 | + } |
| 143 | + |
| 144 | + @Test |
| 145 | + public void testIsTopLevelEntry() { |
| 146 | + Assert.assertTrue(OsgiRegistry.isPackageLevelEntry("a", "/a/Foo.class")); |
| 147 | + } |
| 148 | + |
| 149 | + @Test |
| 150 | + public void testIsTopLevelEntrySequenceRepeats() { |
| 151 | + Assert.assertFalse(OsgiRegistry.isPackageLevelEntry("o", "/a/Foo.class")); |
| 152 | + } |
| 153 | + |
| 154 | + @Test |
| 155 | + public void testIsTopLevelEntryNoSlash() { |
| 156 | + Assert.assertTrue(OsgiRegistry.isPackageLevelEntry("a", "a/Foo.class")); |
| 157 | + } |
| 158 | + |
| 159 | + @Test |
| 160 | + public void testIsTopLevelEntrySequenceRepeatsNoSlash() { |
| 161 | + Assert.assertFalse(OsgiRegistry.isPackageLevelEntry("o", "a/Foo.class")); |
| 162 | + } |
| 163 | + |
| 164 | + @Test |
| 165 | + public void testIsTopLevelEntrySlash() { |
| 166 | + Assert.assertTrue(OsgiRegistry.isPackageLevelEntry("a/", "/a/Foo.class")); |
| 167 | + } |
| 168 | + |
| 169 | + @Test |
| 170 | + public void testIsTopLevelEntrySequenceRepeatsSlash() { |
| 171 | + Assert.assertFalse(OsgiRegistry.isPackageLevelEntry("o/", "/a/Foo.class")); |
| 172 | + } |
| 173 | + |
| 174 | + @Test |
| 175 | + public void testIsTopLevelEntryRoot() { |
| 176 | + Assert.assertTrue(OsgiRegistry.isPackageLevelEntry("/", "/Foo.class")); |
| 177 | + } |
| 178 | + |
| 179 | + @Test |
| 180 | + public void testIsTopLevelEntryRootFalse() { |
| 181 | + Assert.assertFalse(OsgiRegistry.isPackageLevelEntry("/", "/a/Foo.class")); |
| 182 | + } |
| 183 | + |
| 184 | +} |
0 commit comments