test/sun/management/jdp/JdpUnitTest.java

Print this page
rev 8717 : 8014506: Test of Jdp feature
Reviewed-by:
Contributed-by: Alex Schenkman <alex.schenkman@oracle.com>


  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 import java.io.IOException;
  25 import java.net.InetAddress;
  26 import java.util.UUID;
  27 
  28 import sun.management.jdp.JdpController;
  29 import sun.management.jdp.JdpPacket;
  30 import sun.management.jdp.JdpJmxPacket;
  31 import sun.management.jdp.JdpException;
  32 
  33 public class JdpUnitTest {
  34 
  35 
  36     static byte[] russian_name = {(byte)0xd0,(byte)0xbf,(byte)0xd1,(byte)0x80,(byte)0xd0,(byte)0xbe,(byte)0xd0,(byte)0xb2,
  37                                   (byte)0xd0,(byte)0xb5,(byte)0xd1,(byte)0x80,(byte)0xd0,(byte)0xba,(byte)0xd0,(byte)0xb0,
  38                                   (byte)0x20,(byte)0xd1,(byte)0x81,(byte)0xd0,(byte)0xb2,(byte)0xd1,(byte)0x8f,(byte)0xd0,
  39                                   (byte)0xb7,(byte)0xd0,(byte)0xb8,(byte)0x0a};
  40 
  41     /**
  42      * This test tests that complete packet is build correctly
  43      */
  44     public static void PacketBuilderTest()
  45         throws IOException, JdpException {
  46 
  47         /* Complete packet test */
  48         {
  49             JdpJmxPacket p1 = new JdpJmxPacket(UUID.randomUUID(), "fake://unit-test");
  50             p1.setMainClass("FakeUnitTest");
  51             p1.setInstanceName( new String(russian_name,"UTF-8"));
  52             byte[] b = p1.getPacketData();
  53 
  54             JdpJmxPacket p2 = new JdpJmxPacket(b);
  55             JdpDoSomething.printJdpPacket(p1);
  56             JdpDoSomething.compaireJdpPacketEx(p1, p2);
  57         }
  58 
  59         /*Missed field packet test*/
  60         {
  61             JdpJmxPacket p1 = new JdpJmxPacket(UUID.randomUUID(), "fake://unit-test");
  62             p1.setMainClass("FakeUnitTest");
  63             p1.setInstanceName(null);
  64             byte[] b = p1.getPacketData();
  65 
  66             JdpJmxPacket p2 = new JdpJmxPacket(b);
  67             JdpDoSomething.printJdpPacket(p1);
  68             JdpDoSomething.compaireJdpPacketEx(p1, p2);
  69         }
  70 
  71          System.out.println("OK: Test passed");




  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 import java.io.IOException;
  25 import java.net.InetAddress;
  26 import java.util.UUID;
  27 
  28 import sun.management.jdp.JdpController;
  29 import sun.management.jdp.JdpPacket;
  30 import sun.management.jdp.JdpJmxPacket;
  31 import sun.management.jdp.JdpException;
  32 
  33 public class JdpUnitTest {
  34 
  35 
  36     static byte[] russian_name = {(byte) 0xd0, (byte) 0xbf, (byte) 0xd1, (byte) 0x80, (byte) 0xd0, (byte) 0xbe, (byte) 0xd0, (byte) 0xb2,
  37             (byte) 0xd0, (byte) 0xb5, (byte) 0xd1, (byte) 0x80, (byte) 0xd0, (byte) 0xba, (byte) 0xd0, (byte) 0xb0,
  38             (byte) 0x20, (byte) 0xd1, (byte) 0x81, (byte) 0xd0, (byte) 0xb2, (byte) 0xd1, (byte) 0x8f, (byte) 0xd0,
  39             (byte) 0xb7, (byte) 0xd0, (byte) 0xb8, (byte) 0x0a};
  40 
  41     /**
  42      * This test tests that complete packet is build correctly
  43      */
  44     public static void PacketBuilderTest()
  45             throws IOException, JdpException {
  46 
  47         /* Complete packet test */
  48         {
  49             JdpJmxPacket p1 = new JdpJmxPacket(UUID.randomUUID(), "fake://unit-test");
  50             p1.setMainClass("FakeUnitTest");
  51             p1.setInstanceName(new String(russian_name, "UTF-8"));
  52             byte[] b = p1.getPacketData();
  53 
  54             JdpJmxPacket p2 = new JdpJmxPacket(b);
  55             JdpDoSomething.printJdpPacket(p1);
  56             JdpDoSomething.compaireJdpPacketEx(p1, p2);
  57         }
  58 
  59         /*Missed field packet test*/
  60         {
  61             JdpJmxPacket p1 = new JdpJmxPacket(UUID.randomUUID(), "fake://unit-test");
  62             p1.setMainClass("FakeUnitTest");
  63             p1.setInstanceName(null);
  64             byte[] b = p1.getPacketData();
  65 
  66             JdpJmxPacket p2 = new JdpJmxPacket(b);
  67             JdpDoSomething.printJdpPacket(p1);
  68             JdpDoSomething.compaireJdpPacketEx(p1, p2);
  69         }
  70 
  71         System.out.println("OK: Test passed");