Path: blob/master/test/jdk/sun/management/jdp/JdpTestUtilTest.java
41149 views
/*1* Copyright (c) 2012, 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*/222324import org.testng.annotations.Test;2526import java.io.UnsupportedEncodingException;27import java.util.Map;2829import static jdk.test.lib.Asserts.assertEquals;303132/*33Unit test for the utility functions in JdpTestUtil.34These are not meant to be by automatically run by JTREG.35They exists to support test development and should be run by the test developer.36*/3738public class JdpTestUtilTest {3940@Test41public void testDecodeEntry() throws UnsupportedEncodingException {42byte[] data = {'x', 0, 4, 'a', 'l', 'e', 'x'};43String result = JdpTestUtil.decodeEntry(data, 1);44assertEquals("alex", result);45}4647@Test48public void testDecode2ByteInt() {49byte[] data = {'x', (byte) 0xff, (byte) 0xff};50int value = JdpTestUtil.decode2ByteInt(data, 1);51assertEquals(65535, value);52}5354@Test55public void testDecode4ByteInt() {56byte[] data = {'x', (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff};57int value = JdpTestUtil.decode4ByteInt(data, 1);58assertEquals(0xffffffff, value);5960}6162@Test63public void testReadRawPayload() throws UnsupportedEncodingException {64byte[] data = {0, 3, 'f', 'o', 'o', 0, 4, 'b', 'a', 'r', 's'};65Map<String, String> payload = JdpTestUtil.readRawPayload(data, data.length);6667assertEquals(1, payload.size());68assertEquals("bars", payload.get("foo"));69}7071@Test72public void testReadPayload() throws UnsupportedEncodingException {73byte[] data = {1, 2, 3, 4, 1, 2, 0, 3, 'f', 'o', 'o', 0, 4, 'b', 'a', 'r', 's'};74Map<String, String> payload = JdpTestUtil.readPayload(data);7576assertEquals(1, payload.size());77assertEquals("bars", payload.get("foo"));78}7980}818283