⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 clientpropertytest.java

📁 java开源的企业总线.xmlBlaster
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
      }      {         ClientProperty clientProperty = new ClientProperty("key", Constants.TYPE_BYTE, null);         assertEquals("", "key", clientProperty.getName());         assertEquals("", "byte", clientProperty.getType());         assertEquals("", null, clientProperty.getEncoding());         assertEquals("", null, clientProperty.getValueRaw());         assertEquals("", null, clientProperty.getStringValue());         assertEquals("", null, clientProperty.getObjectValue());         clientProperty.setValue("6");         String xml = clientProperty.toXml();         assertEquals("", "6", clientProperty.getValueRaw());         assertXMLEqual("comparing test xml to control xml",                        "<clientProperty name='key' type='byte'>6</clientProperty>",                        xml);         assertTrue("", (byte)6 == clientProperty.getByteValue());         assertTrue("", clientProperty.getObjectValue() instanceof Byte);         System.out.println(xml);      }      {         ClientProperty clientProperty = new ClientProperty("key", Constants.TYPE_LONG, null);         assertEquals("", "key", clientProperty.getName());         assertEquals("", "long", clientProperty.getType());         assertEquals("", null, clientProperty.getEncoding());         assertEquals("", null, clientProperty.getValueRaw());         assertEquals("", null, clientProperty.getStringValue());         assertEquals("", null, clientProperty.getObjectValue());         clientProperty.setValue("888888");         String xml = clientProperty.toXml();         assertEquals("", "888888", clientProperty.getValueRaw());         assertXMLEqual("comparing test xml to control xml",                        "<clientProperty name='key' type='long'>888888</clientProperty>",                        xml);         assertTrue("", 888888 == clientProperty.getLongValue());         assertTrue("", clientProperty.getObjectValue() instanceof Long);         System.out.println(xml);      }      {         ClientProperty clientProperty = new ClientProperty("key", Constants.TYPE_SHORT, null);         assertEquals("", "key", clientProperty.getName());         assertEquals("", "short", clientProperty.getType());         assertEquals("", null, clientProperty.getEncoding());         assertEquals("", null, clientProperty.getValueRaw());         assertEquals("", null, clientProperty.getStringValue());         assertEquals("", null, clientProperty.getObjectValue());         clientProperty.setValue("12");         String xml = clientProperty.toXml();         assertEquals("", "12", clientProperty.getValueRaw());         assertXMLEqual("comparing test xml to control xml",                        "<clientProperty name='key' type='short'>12</clientProperty>",                        xml);         assertTrue("", 12 == clientProperty.getShortValue());         assertTrue("", clientProperty.getObjectValue() instanceof Short);         System.out.println(xml);      }      {         ClientProperty clientProperty = new ClientProperty("key", null, null);         assertEquals("", "key", clientProperty.getName());         assertEquals("", null, clientProperty.getType());         assertEquals("", null, clientProperty.getEncoding());         assertEquals("", null, clientProperty.getValueRaw());         assertEquals("", null, clientProperty.getStringValue());         assertEquals("", null, clientProperty.getObjectValue());         byte[] bb = new byte[6];         bb[0] = 0;         bb[1] = 'A';         bb[2] = 0;         bb[3] = 99;         bb[4] = 0;         bb[5] = 0;         clientProperty.setValue(bb);         assertEquals("", "byte[]", clientProperty.getType());         assertEquals("", Constants.ENCODING_BASE64, clientProperty.getEncoding());         assertEquals("", true, clientProperty.isBase64());         String xml = clientProperty.toXml();         byte[] newVal = clientProperty.getBlobValue();         for (int i=0; i<bb.length; i++)             assertTrue("Index #"+i, bb[i] == newVal[i]);         assertXpathExists("/clientProperty[@name='key']", xml);         assertXpathExists("/clientProperty[@type='"+Constants.TYPE_BLOB+"']", xml);         assertXpathExists("/clientProperty[@encoding='"+Constants.ENCODING_BASE64+"']", xml);         assertEquals("", "AEEAYwAA", clientProperty.getValueRaw());         assertXMLEqual("comparing test xml to control xml",                        "<clientProperty name='key' type='byte[]' encoding='base64'>AEEAYwAA</clientProperty>",                        xml);         assertTrue("", clientProperty.getObjectValue() instanceof byte[]);         newVal = (byte[])clientProperty.getObjectValue();         for (int i=0; i<bb.length; i++)             assertTrue("Index #"+i, bb[i] == newVal[i]);         System.out.println(xml);      }   }   public void testClientPropertyParsing() throws Exception {            String xml =  "<qos>\n" +         "  <isPublish/>\n" +          "  <clientProperty name='StringKey' type=''><![CDATA[Bla<BlaBla]]></clientProperty>\n" +          "</qos>";                  MsgQosSaxFactory parser = new MsgQosSaxFactory(this.glob);      MsgQosData data = parser.readObject(xml);      ClientProperty prop = data.getClientProperty("StringKey");      System.out.println(prop.toXml());      assertEquals("", true, prop.isBase64());         }   public void testClientPropertyParsingWithUntrimmedSpaces() throws Exception {      MsgQosData data = new MsgQosData(this.glob, MethodName.PUBLISH);      String name1 = "leadingSpaces";      String val1 = "  val1";      String name2 = "endingSpaces";      String val2 = "val2  ";      String name3 = "bothSpaces";      String val3 = "  val3  ";      String name4 = "singleSpace";      String val4 = " val4 ";      ClientProperty prop1 = new ClientProperty(name1, null, null, val1);      ClientProperty prop2 = new ClientProperty(name2, null, null, val2);      ClientProperty prop3 = new ClientProperty(name3, null, null, val3);      ClientProperty prop4 = new ClientProperty(name4, null, null, val4);      data.addClientProperty(prop1);      data.addClientProperty(prop2);      data.addClientProperty(prop3);      data.addClientProperty(prop4);      String xml = data.toXml();      System.out.println("The content of the qos is '" + xml + "'");      MsgQosSaxFactory parser = new MsgQosSaxFactory(this.glob);      MsgQosData data1 = parser.readObject(xml);      assertEquals(name1, val1, data1.getClientProperty(name1).getStringValue());      assertEquals(name2, val2, data1.getClientProperty(name2).getStringValue());      assertEquals(name3, val3, data1.getClientProperty(name3).getStringValue());      assertEquals(name4, val4, data1.getClientProperty(name4).getStringValue());         }   public void testClientPropertyEnclosedXmlTree() throws Exception {            String xml =  "<qos>\n" +         "  <isPublish/>\n" +          "  <clientProperty name='StringKey' type=''><BlaBla attr1='val1' attr2=' val2 '> Something </BlaBla></clientProperty>\n" +          "</qos>";                  MsgQosSaxFactory parser = new MsgQosSaxFactory(this.glob);      MsgQosData data = parser.readObject(xml);      ClientProperty prop = data.getClientProperty("StringKey");      System.out.println(prop.toXml());      // assertEquals("", true, prop.isBase64());                  String val = "<BlaBla attr1='val1' attr2=' val2 '> Something </BlaBla>";      prop = new ClientProperty("StringKey", null, Constants.ENCODING_FORCE_PLAIN, val);      System.out.println(prop.toXml());      xml =  "<qos>\n" +      "  <isPublish/>\n" +       "  <clientProperty name='StringKey' type='' encoding='forcePlain'><qos attr1='val1' attr2=' val2 '> Something </qos></clientProperty>\n" +       "</qos>";                  parser = new MsgQosSaxFactory(this.glob);      data = parser.readObject(xml);      prop = data.getClientProperty("StringKey");      System.out.println(prop.toXml());            xml =  "<qos>\n" +      "  <isPublish/>\n" +       "  <clientProperty name='StringKey' type='' encoding='forcePlain'><clientProperty name='aaa' type='' encoding=''>Something</clientProperty></clientProperty>\n" +       "</qos>";                  parser = new MsgQosSaxFactory(this.glob);      data = parser.readObject(xml);      prop = data.getClientProperty("StringKey");      System.out.println(prop.toXml());            System.out.println("END");   }   /**    * <pre>    *  java org.xmlBlaster.test.classtest.ClientPropertyTest    * </pre>    */   public static void main(String args[])   {      try {         ClientPropertyTest testSub = new ClientPropertyTest("ClientPropertyTest");         testSub.setUp();         testSub.testClientPropertyEnclosedXmlTree();         testSub.testClientProperty();         testSub.testClientPropertyEncoding();         testSub.testClientPropertyCtorEncoding();         testSub.testClientPropertyTypes();         testSub.testClientPropertyAutoEncoding();         testSub.testClientPropertyParsing();         testSub.testClientPropertyParsingWithUntrimmedSpaces();         testSub.tearDown();      }      catch(Throwable e) {         e.printStackTrace();         fail(e.toString());      }   }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -