Path: blob/master/test/functional/cmdLineTests/shareClassTests/SCHelperCompatTests/TokenIncompatibilityTest.java
6004 views
/*******************************************************************************1* Copyright (c) 2005, 2020 IBM Corp. and others2*3* This program and the accompanying materials are made available under4* the terms of the Eclipse Public License 2.0 which accompanies this5* distribution and is available at https://www.eclipse.org/legal/epl-2.0/6* or the Apache License, Version 2.0 which accompanies this distribution and7* is available at https://www.apache.org/licenses/LICENSE-2.0.8*9* This Source Code may also be made available under the following10* Secondary Licenses when the conditions for such availability set11* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU12* General Public License, version 2 with the GNU Classpath13* Exception [1] and GNU General Public License, version 2 with the14* OpenJDK Assembly Exception [2].15*16* [1] https://www.gnu.org/software/classpath/license.html17* [2] http://openjdk.java.net/legal/assembly-exception.html18*19* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception20*******************************************************************************/21import java.net.URL;2223import CustomCLs.CustomTokenClassLoader;24import CustomCLs.CustomURLClassLoader;25import CustomCLs.CustomURLLoader;26import Utilities.StringManipulator;27import Utilities.URLClassPathCreator;2829/**30* @author Matthew Kilner31*/32public class TokenIncompatibilityTest {3334StringManipulator manipulator = new StringManipulator();3536public static void main(String[] args) {3738TokenIncompatibilityTest test = new TokenIncompatibilityTest();3940test.run();41}4243public void run(){44boolean passed = true;4546URLClassPathCreator pathCreator = new URLClassPathCreator("./Pets;./Sports;");4748CustomTokenClassLoader loader = new CustomTokenClassLoader(pathCreator.createURLClassPath());4950String[] classesToLoad = new String[]{"Dog","SpeedSkating"};5152String tok = "FindStore";53loader.setToken(tok);54for(int index = 0; index < classesToLoad.length; index++){55try{56loader.loadClass(classesToLoad[index]);57} catch(ClassNotFoundException e){58e.printStackTrace();59}60}61for(int index = 0; index < classesToLoad.length; index++){62if(true != loader.isClassInSharedCache(tok, classesToLoad[index])){63System.out.println("\nClass: "+classesToLoad[index]+" not in cache");64passed = false;65}66}6768pathCreator = new URLClassPathCreator("./Pets;");69CustomURLClassLoader urlCl = new CustomURLClassLoader(pathCreator.createURLClassPath());70if(true == urlCl.isClassInSharedCache("Dog")){71passed = false;72System.out.println("\nURLClassLoader succesfully loaded class stored with token.");73}7475pathCreator = new URLClassPathCreator("./Sports;");76CustomURLLoader urlL = new CustomURLLoader(pathCreator.createURLClassPath());77if(true == urlL.isClassInSharedCache(0,"Dog")){78passed = false;79System.out.println("\nURLLoader succesfully loaded class stored with token.");80}8182//Load with URLCP83try{84urlCl.loadClass("Cat");85} catch(ClassNotFoundException e){86e.printStackTrace();87}8889//Load with URLL90urlL.loadClassFrom("Cricket",0);9192//Find with Token93if(true == loader.isClassInSharedCache(tok, "Cat")){94passed = false;95System.out.println("\nTokenLoader found class loaded by URLClassLoader");96}9798if(true == loader.isClassInSharedCache(tok, "Cricket")){99passed = false;100System.out.println("\nTokenLoader found class loaded by URLLoader");101}102103//Find with token == url104pathCreator = new URLClassPathCreator("./Pets;");105URL[] urlarray = pathCreator.createURLClassPath();106String urlToken = urlarray[0].toString();107if(true == loader.isClassInSharedCache(urlToken, "Cricket")){108passed = false;109System.out.println("\nTokenLoader found class loaded by URLLoader using a token that looked like a url");110}111112if(passed){113System.out.println("\nTEST PASSED");114} else {115System.out.println("\nTEST FAILED");116}117}118}119120121