Path: blob/master/test/functional/cmdLineTests/shareClassTests/utils/src/Utilities/Verifier.java
6005 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*******************************************************************************/21package Utilities;2223import java.io.FileInputStream;24import java.net.URL;25import java.util.Properties;2627import CustomCLs.CustomURLClassLoader;2829/**30* @author Matthew Kilner31*/32public class Verifier {3334StringManipulator manipulator = new StringManipulator();3536public static void main(String[] args) {3738if(args.length != 2){39System.out.println("\n Incorrect usage");40System.out.println("\n Please specifiy -testfile <filename>");41}4243Verifier test = new Verifier();4445String testFile = args[1];4647test.testWrapper(testFile);4849}5051public void testWrapper(String testFileName){5253System.out.println("\n** Running Verifier for properties: "+testFileName+"\n");5455Properties props = new Properties();56try{57FileInputStream PropertiesFile = new FileInputStream(testFileName);58props.load(PropertiesFile);5960PropertiesFile.close();61} catch (Exception e){62e.printStackTrace();63}6465String classPath = props.getProperty("ClassPath");6667String nctls = props.getProperty("NumberOfClassesToVerify");68Integer i = Integer.valueOf(nctls);69int classesToVerifyCount = i.intValue();7071String[] classesToVerify = new String[classesToVerifyCount];72String classesString = props.getProperty("ClassesToVerify");73for(int index = 0; index < classesToVerifyCount; index ++){74classesToVerify[index] = manipulator.getStringElement(index, classesString);75}7677String[] results = new String[classesToVerifyCount];78String verifiersResults = props.getProperty("Results");79for(int index = 0; index < classesToVerifyCount; index++){80results[index] = manipulator.getStringElement(index, verifiersResults);81}8283boolean passed = executeTest(classPath, classesToVerify, results);8485if(passed){86System.out.println("\nTEST PASSED");87} else {88System.out.println("\nTEST FAILED");89}90}9192public boolean executeTest(String classpath, String[] classesToVerify, String[] results){9394System.out.println("\nCreating Verifier.....");95URLClassPathCreator vfPathCreator = new URLClassPathCreator(classpath);96URL[] vfPath;97vfPath = vfPathCreator.createURLClassPath();98CustomURLClassLoader verifier = new CustomURLClassLoader(vfPath, this.getClass().getClassLoader());99100System.out.println("\nRunning Verifier.....");101boolean result = true;102for(int cIndex = 0; cIndex < classesToVerify.length; cIndex++){103String className = classesToVerify[cIndex];104if(className != null){105String expectedResult = results[cIndex];106String testResult = String.valueOf(verifier.isClassInSharedCache(className));107if(!(expectedResult.equals(testResult))){108System.out.println("\nFailure testing class: "+className+" result: "+testResult+" expecting: "+expectedResult);109result = false;110}111}112}113return result;114}115}116117118