Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/test/functional/cmdLineTests/shareClassTests/SCHelperCompatTests/TokenIncompatibilityTest.java
6004 views
1
/*******************************************************************************
2
* Copyright (c) 2005, 2020 IBM Corp. and others
3
*
4
* This program and the accompanying materials are made available under
5
* the terms of the Eclipse Public License 2.0 which accompanies this
6
* distribution and is available at https://www.eclipse.org/legal/epl-2.0/
7
* or the Apache License, Version 2.0 which accompanies this distribution and
8
* is available at https://www.apache.org/licenses/LICENSE-2.0.
9
*
10
* This Source Code may also be made available under the following
11
* Secondary Licenses when the conditions for such availability set
12
* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
13
* General Public License, version 2 with the GNU Classpath
14
* Exception [1] and GNU General Public License, version 2 with the
15
* OpenJDK Assembly Exception [2].
16
*
17
* [1] https://www.gnu.org/software/classpath/license.html
18
* [2] http://openjdk.java.net/legal/assembly-exception.html
19
*
20
* 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-exception
21
*******************************************************************************/
22
import java.net.URL;
23
24
import CustomCLs.CustomTokenClassLoader;
25
import CustomCLs.CustomURLClassLoader;
26
import CustomCLs.CustomURLLoader;
27
import Utilities.StringManipulator;
28
import Utilities.URLClassPathCreator;
29
30
/**
31
* @author Matthew Kilner
32
*/
33
public class TokenIncompatibilityTest {
34
35
StringManipulator manipulator = new StringManipulator();
36
37
public static void main(String[] args) {
38
39
TokenIncompatibilityTest test = new TokenIncompatibilityTest();
40
41
test.run();
42
}
43
44
public void run(){
45
boolean passed = true;
46
47
URLClassPathCreator pathCreator = new URLClassPathCreator("./Pets;./Sports;");
48
49
CustomTokenClassLoader loader = new CustomTokenClassLoader(pathCreator.createURLClassPath());
50
51
String[] classesToLoad = new String[]{"Dog","SpeedSkating"};
52
53
String tok = "FindStore";
54
loader.setToken(tok);
55
for(int index = 0; index < classesToLoad.length; index++){
56
try{
57
loader.loadClass(classesToLoad[index]);
58
} catch(ClassNotFoundException e){
59
e.printStackTrace();
60
}
61
}
62
for(int index = 0; index < classesToLoad.length; index++){
63
if(true != loader.isClassInSharedCache(tok, classesToLoad[index])){
64
System.out.println("\nClass: "+classesToLoad[index]+" not in cache");
65
passed = false;
66
}
67
}
68
69
pathCreator = new URLClassPathCreator("./Pets;");
70
CustomURLClassLoader urlCl = new CustomURLClassLoader(pathCreator.createURLClassPath());
71
if(true == urlCl.isClassInSharedCache("Dog")){
72
passed = false;
73
System.out.println("\nURLClassLoader succesfully loaded class stored with token.");
74
}
75
76
pathCreator = new URLClassPathCreator("./Sports;");
77
CustomURLLoader urlL = new CustomURLLoader(pathCreator.createURLClassPath());
78
if(true == urlL.isClassInSharedCache(0,"Dog")){
79
passed = false;
80
System.out.println("\nURLLoader succesfully loaded class stored with token.");
81
}
82
83
//Load with URLCP
84
try{
85
urlCl.loadClass("Cat");
86
} catch(ClassNotFoundException e){
87
e.printStackTrace();
88
}
89
90
//Load with URLL
91
urlL.loadClassFrom("Cricket",0);
92
93
//Find with Token
94
if(true == loader.isClassInSharedCache(tok, "Cat")){
95
passed = false;
96
System.out.println("\nTokenLoader found class loaded by URLClassLoader");
97
}
98
99
if(true == loader.isClassInSharedCache(tok, "Cricket")){
100
passed = false;
101
System.out.println("\nTokenLoader found class loaded by URLLoader");
102
}
103
104
//Find with token == url
105
pathCreator = new URLClassPathCreator("./Pets;");
106
URL[] urlarray = pathCreator.createURLClassPath();
107
String urlToken = urlarray[0].toString();
108
if(true == loader.isClassInSharedCache(urlToken, "Cricket")){
109
passed = false;
110
System.out.println("\nTokenLoader found class loaded by URLLoader using a token that looked like a url");
111
}
112
113
if(passed){
114
System.out.println("\nTEST PASSED");
115
} else {
116
System.out.println("\nTEST FAILED");
117
}
118
}
119
}
120
121