Path: blob/master/test/jdk/sun/management/StackTraceElementCompositeData/CompatibilityTest.java
41149 views
/*1* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import java.util.HashMap;24import java.util.Map;25import javax.management.openmbean.CompositeData;26import javax.management.openmbean.CompositeDataSupport;27import javax.management.openmbean.CompositeType;28import javax.management.openmbean.OpenType;29import javax.management.openmbean.SimpleType;3031import sun.management.StackTraceElementCompositeData;3233import org.testng.annotations.*;34import static org.testng.Assert.*;3536/*37* @test38* @bug 8139587 821219739* @modules java.management/sun.management40* @summary Check backward compatibility of StackTraceElementCompositeData41* @author Jaroslav Bachorik42*43* @run testng CompatibilityTest44*/4546public class CompatibilityTest {47private static CompositeType compositeTypeV6;48private static CompositeType compositeType;4950// Attribute names51private static final String CLASS_LOADER_NAME = "classLoaderName";52private static final String MODULE_NAME = "moduleName";53private static final String MODULE_VERSION = "moduleVersion";54private static final String CLASS_NAME = "className";55private static final String METHOD_NAME = "methodName";56private static final String FILE_NAME = "fileName";57private static final String LINE_NUMBER = "lineNumber";58private static final String NATIVE_METHOD = "nativeMethod";5960@BeforeClass61public static void setup() throws Exception {62String[] v6Names = {63CLASS_NAME, METHOD_NAME, FILE_NAME, NATIVE_METHOD, LINE_NUMBER64};65String[] names = {66CLASS_LOADER_NAME, MODULE_NAME, MODULE_VERSION,67CLASS_NAME, METHOD_NAME, FILE_NAME, NATIVE_METHOD, LINE_NUMBER68};69compositeTypeV6 = new CompositeType(70StackTraceElement.class.getName(),71"StackTraceElement",72v6Names,73v6Names,74new OpenType[] {75SimpleType.STRING,76SimpleType.STRING,77SimpleType.STRING,78SimpleType.BOOLEAN,79SimpleType.INTEGER80}81);82compositeType = new CompositeType(83StackTraceElement.class.getName(),84"StackTraceElement",85names,86names,87new OpenType[] {88SimpleType.STRING,89SimpleType.STRING,90SimpleType.STRING,91SimpleType.STRING,92SimpleType.STRING,93SimpleType.STRING,94SimpleType.BOOLEAN,95SimpleType.INTEGER96}97);98}99100private static CompositeData makeCompositeDataV6() throws Exception {101Map<String, Object> itemsV6 = new HashMap<>();102itemsV6.put(CLASS_NAME, "MyClass");103itemsV6.put(METHOD_NAME, "myMethod");104itemsV6.put(FILE_NAME, "MyClass.java");105itemsV6.put(NATIVE_METHOD, false);106itemsV6.put(LINE_NUMBER, 123);107108return new CompositeDataSupport(compositeTypeV6, itemsV6);109}110111private static CompositeData makeCompositeData() throws Exception {112Map<String, Object> items = new HashMap<>();113items.put(CLASS_LOADER_NAME, "app");114items.put(MODULE_NAME, "m");115items.put(MODULE_VERSION, "1.0");116items.put(CLASS_NAME, "MyClass");117items.put(METHOD_NAME, "myMethod");118items.put(FILE_NAME, "MyClass.java");119items.put(NATIVE_METHOD, false);120items.put(LINE_NUMBER, 123);121122return new CompositeDataSupport(compositeType, items);123}124125@Test126public void testV6Compatibility() throws Exception {127StackTraceElement ste = StackTraceElementCompositeData.from(makeCompositeDataV6());128129assertNotNull(ste);130assertEquals(ste.getClassName(), "MyClass");131assertEquals(ste.getMethodName(), "myMethod");132assertEquals(ste.getFileName(), "MyClass.java");133assertEquals(ste.isNativeMethod(), false);134assertEquals(ste.getLineNumber(), 123);135136assertNull(ste.getModuleName());137assertNull(ste.getModuleVersion());138}139140@Test141public void test() throws Exception {142StackTraceElement ste = StackTraceElementCompositeData.from(makeCompositeData());143144assertNotNull(ste);145146assertEquals(ste.getModuleName(), "m");147assertEquals(ste.getModuleVersion(), "1.0");148assertEquals(ste.getClassLoaderName(), "app");149150assertEquals(ste.getClassName(), "MyClass");151assertEquals(ste.getMethodName(), "myMethod");152assertEquals(ste.getFileName(), "MyClass.java");153assertEquals(ste.isNativeMethod(), false);154assertEquals(ste.getLineNumber(), 123);155}156157@Test158public void testCompositeData() throws Exception {159StackTraceElement ste = new StackTraceElement("app",160"m", "1.0",161"p.MyClass", "myMethod",162"MyClass.java", 123);163CompositeData cd = StackTraceElementCompositeData.toCompositeData(ste);164StackTraceElement ste1 = StackTraceElementCompositeData.from(cd);165assertEquals(ste, ste1);166}167}168169170171