From 37e47101836b20ee495962a6d813a9d5f8d9109a Mon Sep 17 00:00:00 2001 From: sg481n Date: Thu, 3 Aug 2017 17:44:44 -0400 Subject:  [AAF-23] Initial code import MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I8c0dc03058ae4fbb85c28a050bdd77e6c372d6c3 Signed-off-by: sg481n --- .../src/test/java/com/data/test/JU_FromJSON.java | 271 ++++++++++++++++++ .../src/test/java/com/data/test/JU_FromXML.java | 262 ++++++++++++++++++ rosetta/src/test/java/com/data/test/JU_JSON.java | 138 ++++++++++ rosetta/src/test/java/com/data/test/JU_Ladder.java | 80 ++++++ rosetta/src/test/java/com/data/test/JU_Nulls.java | 72 +++++ .../src/test/java/com/data/test/JU_RosettaDF.java | 165 +++++++++++ rosetta/src/test/java/com/data/test/JU_Saved.java | 107 ++++++++ .../src/test/java/com/data/test/JU_Stream2Obj.java | 126 +++++++++ rosetta/src/test/java/com/data/test/JU_Struct.java | 76 ++++++ rosetta/src/test/java/com/data/test/JU_Types.java | 304 +++++++++++++++++++++ rosetta/src/test/java/com/data/test/OutDump.java | 93 +++++++ rosetta/src/test/java/com/data/test/Report.java | 69 +++++ .../test/java/com/data/test/obj/MultiMarshal.java | 43 +++ .../test/java/com/data/test/obj/SingleMarshal.java | 93 +++++++ 14 files changed, 1899 insertions(+) create mode 100644 rosetta/src/test/java/com/data/test/JU_FromJSON.java create mode 100644 rosetta/src/test/java/com/data/test/JU_FromXML.java create mode 100644 rosetta/src/test/java/com/data/test/JU_JSON.java create mode 100644 rosetta/src/test/java/com/data/test/JU_Ladder.java create mode 100644 rosetta/src/test/java/com/data/test/JU_Nulls.java create mode 100644 rosetta/src/test/java/com/data/test/JU_RosettaDF.java create mode 100644 rosetta/src/test/java/com/data/test/JU_Saved.java create mode 100644 rosetta/src/test/java/com/data/test/JU_Stream2Obj.java create mode 100644 rosetta/src/test/java/com/data/test/JU_Struct.java create mode 100644 rosetta/src/test/java/com/data/test/JU_Types.java create mode 100644 rosetta/src/test/java/com/data/test/OutDump.java create mode 100644 rosetta/src/test/java/com/data/test/Report.java create mode 100644 rosetta/src/test/java/com/data/test/obj/MultiMarshal.java create mode 100644 rosetta/src/test/java/com/data/test/obj/SingleMarshal.java (limited to 'rosetta/src/test/java') diff --git a/rosetta/src/test/java/com/data/test/JU_FromJSON.java b/rosetta/src/test/java/com/data/test/JU_FromJSON.java new file mode 100644 index 0000000..4e3d211 --- /dev/null +++ b/rosetta/src/test/java/com/data/test/JU_FromJSON.java @@ -0,0 +1,271 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.data.test; + +import java.io.Reader; +import java.io.StringReader; + +import org.junit.Test; + +import com.att.inno.env.Env; +import com.att.inno.env.LogTarget; +import com.att.inno.env.TimeTaken; +import com.att.inno.env.Trans; +import com.att.inno.env.impl.EnvFactory; +import com.att.inno.env.jaxb.JAXBmar; +import com.att.inno.env.util.IndentPrintWriter; +import com.att.inno.env.util.StringBuilderWriter; +import com.att.rosetta.InJson; +import com.att.rosetta.Out; +import com.att.rosetta.OutJson; +import com.att.rosetta.OutRaw; +import com.att.rosetta.OutXML; + +import junit.framework.Assert; +import s.xsd.LargerData; +import s.xsd.SampleData; + +public class JU_FromJSON { + private static int ITERATIONS = 10000; + static String str = "{\"SampleData\":[" + + "{\"id\":\"sd object \\\"1\\\"\",\"date\":1316084944213,\"item\":[\"Item 1.1\",\"Item 1.2\"]}," + + "{\"id\":\"sd object \\\"2\\\"\",\"date\":1316084945343,\"item\":[\"Item 2.1\",\"Item 2.2\"]}],\"fluff\":\"MyFluff\"}"; + InJson inJSON = new InJson(); + + @Test + public void rawParse() throws Exception { + System.out.println("*** PARSE JSON -> RAW Dump ***"); + System.out.println(str); + StringBuilderWriter sbw = new StringBuilderWriter(); + new OutRaw().extract(new StringReader(str),sbw,inJSON); + System.out.println(sbw.getBuffer()); + } + + @Test + public void parseJSON2Dump() throws Exception { + System.out.println("*** PARSE JSON -> Dump ***"); + System.out.println(str); + StringBuilderWriter sbw = new StringBuilderWriter(1024); + + new OutDump().extract(new StringReader(str), sbw, inJSON); + + System.out.println(sbw.getBuffer()); + } + + @Test + public void nonprettyJSON() throws Exception { + System.out.println("*** JSON -> (Intermediate Stream) -> Non-pretty JSON ***"); + System.out.println(str); + StringBuilderWriter sbw = new StringBuilderWriter(1024); + + Out jout = new OutJson(); + Trans trans; + Report report = new Report(ITERATIONS,"JSON"); + do { + sbw.reset(); + trans = EnvFactory.newTrans(); + Reader sr = new StringReader(str); + TimeTaken tt = trans.start("Parse JSON", Env.JSON); + try { + jout.extract(sr, sbw, inJSON); + } finally { + tt.done(); + } + report.glean(trans,Env.JSON); + } while(report.go()); + + String result = sbw.toString(); + System.out.println(result); + Assert.assertEquals(result, str); + report.report(sbw); + System.out.println(sbw.toString()); + } + + @Test + public void parseJSON2JSON() throws Exception { + System.out.println("*** JSON -> (Intermediate Stream) -> Pretty JSON ***"); + System.out.println(str); + + StringBuilderWriter sbw = new StringBuilderWriter(1024); + + Out jout = new OutJson(); + Trans trans; + Report report = new Report(ITERATIONS,"JSON"); + do { + sbw.reset(); + trans = EnvFactory.newTrans(); + Reader sr = new StringReader(str); + TimeTaken tt = trans.start("Parse JSON", Env.JSON); + try { + jout.extract(sr, sbw, inJSON,true); + } finally { + tt.done(); + } + report.glean(trans,Env.JSON); + } while(report.go()); + + report.report(sbw); + System.out.println(sbw.toString()); + } + + @Test + public void parseJSON2XML() throws Exception { + System.out.println("*** PARSE JSON -> XML ***"); + System.out.println(str); + + StringBuilderWriter sbw = new StringBuilderWriter(1024); + + Out xout = new OutXML("LargerData","xmlns=urn:s:xsd"); + Trans trans; + Report report = new Report(ITERATIONS,"JSON"); + do { + sbw.reset(); + trans = EnvFactory.newTrans(); + Reader sr = new StringReader(str); + TimeTaken tt = trans.start("Parse JSON", Env.JSON); + try { + xout.extract(sr, sbw, inJSON); + } finally { + tt.done(); + } + report.glean(trans,Env.JSON); + } while(report.go()); + + report.report(sbw); + System.out.println(sbw.toString()); + } + + @Test + public void parseJSON2PrettyXML() throws Exception { + System.out.println("*** PARSE JSON -> Pretty XML ***"); + System.out.println(str); + + StringBuilderWriter sbw = new StringBuilderWriter(1024); + IndentPrintWriter ipw = new IndentPrintWriter(sbw); + + Out xout = new OutXML("LargerData","xmlns=urn:s:xsd"); + Trans trans; + Report report = new Report(ITERATIONS,"JSON"); + do { + sbw.reset(); + trans = EnvFactory.newTrans(); + Reader sr = new StringReader(str); + TimeTaken tt = trans.start("Parse JSON", Env.JSON); + try { + xout.extract(sr, ipw, inJSON); + } finally { + tt.done(); + } + report.glean(trans,Env.JSON); + } while(report.go()); + + report.report(sbw); + System.out.println(sbw.toString()); + } + + + @Test + public void jaxbObj2XML() throws Exception { + System.out.println("*** JAXB Object -> XML ***"); + + LargerData ld = new LargerData(); + SampleData sd = new SampleData(); + sd.setDate(System.currentTimeMillis()); + sd.setId("sd object \"1\""); + sd.getItem().add("Item 1.1"); + sd.getItem().add("Item 1.2"); + ld.getSampleData().add(sd); + sd = new SampleData(); + sd.setDate(System.currentTimeMillis()); + sd.setId("sd object \"2\""); + sd.getItem().add("Item 2.1"); + sd.getItem().add("Item 2.2"); + ld.getSampleData().add(sd); + ld.setFluff("MyFluff"); + + JAXBmar jaxBmar = new JAXBmar(LargerData.class); + //jaxBmar.asFragment(true); + //jaxBmar.pretty(true); + StringBuilderWriter sbw = new StringBuilderWriter(1024); + + Trans trans; + Report report = new Report(ITERATIONS,"XML"); + do { + sbw.reset(); + trans = EnvFactory.newTrans(); + TimeTaken tt = trans.start("JAXB", Env.XML); + try { + jaxBmar.marshal(LogTarget.NULL, ld, sbw); + } finally { + tt.done(); + } + report.glean(trans,Env.XML); + } while(report.go()); + + report.report(sbw); + System.out.println(sbw.toString()); + } + + @Test + public void jaxbObj2PrettyXML() throws Exception { + System.out.println("*** JAXB Object -> Pretty XML ***"); + + LargerData ld = new LargerData(); + SampleData sd = new SampleData(); + sd.setDate(System.currentTimeMillis()); + sd.setId("sd object \"1\""); + sd.getItem().add("Item 1.1"); + sd.getItem().add("Item 1.2"); + ld.getSampleData().add(sd); + sd = new SampleData(); + sd.setDate(System.currentTimeMillis()); + sd.setId("sd object \"2\""); + sd.getItem().add("Item 2.1"); + sd.getItem().add("Item 2.2"); + ld.getSampleData().add(sd); + ld.setFluff("MyFluff"); + + JAXBmar jaxBmar = new JAXBmar(LargerData.class); + //jaxBmar.asFragment(true); + jaxBmar.pretty(true); + StringBuilderWriter sbw = new StringBuilderWriter(1024); + + Trans trans; + Report report = new Report(ITERATIONS,"XML"); + do { + sbw.reset(); + trans = EnvFactory.newTrans(); + TimeTaken tt = trans.start("JAXB", Env.XML); + try { + jaxBmar.marshal(LogTarget.NULL, ld, sbw); + } finally { + tt.done(); + } + report.glean(trans,Env.XML); + } while(report.go()); + + report.report(sbw); + System.out.println(sbw.toString()); + } +} diff --git a/rosetta/src/test/java/com/data/test/JU_FromXML.java b/rosetta/src/test/java/com/data/test/JU_FromXML.java new file mode 100644 index 0000000..506b6c8 --- /dev/null +++ b/rosetta/src/test/java/com/data/test/JU_FromXML.java @@ -0,0 +1,262 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.data.test; + +import java.io.Reader; +import java.io.StringReader; + +import org.junit.Test; + +import com.att.inno.env.Env; +import com.att.inno.env.LogTarget; +import com.att.inno.env.TimeTaken; +import com.att.inno.env.Trans; +import com.att.inno.env.Trans.Metric; +import com.att.inno.env.impl.EnvFactory; +import com.att.inno.env.jaxb.JAXBmar; +import com.att.inno.env.jaxb.JAXBumar; +import com.att.inno.env.util.StringBuilderWriter; +import com.att.rosetta.InXML; +import com.att.rosetta.Out; +import com.att.rosetta.OutJson; +import com.att.rosetta.OutRaw; +import com.att.rosetta.OutXML; + +import s.xsd.LargerData; + +public class JU_FromXML { + private static int ITERATIONS = 1; + ; + + private final static String xml = + "\n" + + "\n" + + " \n" + + " sd object 1\n" + + " 1346765355134\n" + + " Item 1.1\n" + + " Item 1.2\n" + + " \n" + + " \n" + + " sd object 2\n" + + " 1346765355134\n" + + " Item 2.1\n" + + " Item 2.2\n" + + " \n" + + " MyFluff\n" + + "\n"; + + + @Test + public void test() throws Exception { + InXML inXML = new InXML(LargerData.class); + + System.out.println(xml); + StringBuilderWriter sbw = new StringBuilderWriter(1024); + + Reader rdr = new StringReader(xml); + + new OutRaw().extract(rdr, sbw, inXML); + System.out.println(sbw.getBuffer()); + } + + + @Test + public void xml2JSON() throws Exception { + System.out.println("*** XML -> JSON (No Warm up) ***"); + Out jout = new OutJson(); + InXML inXML = new InXML(LargerData.class); + + StringBuilderWriter sbw = new StringBuilderWriter(1024); + + Trans trans; + Report report = new Report(ITERATIONS,"XML"); + do { + sbw.reset(); + trans = EnvFactory.newTrans(); + Reader sr = new StringReader(xml); + TimeTaken tt = trans.start("Parse XML", Env.XML); + try { + jout.extract(sr, sbw, inXML); + } finally { + tt.done(); + } + report.glean(trans,Env.XML); + } while(report.go()); + + report.report(sbw); + System.out.println(sbw.toString()); + } + + @Test + public void xml2XML() throws Exception { + System.out.println("*** XML -> (Event Queue) -> XML (No Warm up) ***"); + Out xout = new OutXML("LargerData"); + InXML inXML = new InXML(LargerData.class); + + StringBuilderWriter sbw = new StringBuilderWriter(1024); + + Trans trans; + Report report = new Report(ITERATIONS,"XML"); + do { + sbw.reset(); + trans = EnvFactory.newTrans(); + Reader sr = new StringReader(xml); + TimeTaken tt = trans.start("Parse XML", Env.XML); + try { + xout.extract(sr, sbw, inXML); + } finally { + tt.done(); + } + report.glean(trans,Env.XML); + } while(report.go()); + + report.report(sbw); + System.out.println(sbw.toString()); + } + + + @Test + public void warmup() throws Exception { + if(ITERATIONS>20) { + System.out.println("*** Warmup JAXB ***"); + + JAXBumar jaxbUmar = new JAXBumar(LargerData.class); + JAXBmar jaxBmar = new JAXBmar(LargerData.class); + //jaxBmar.asFragment(true); + //jaxBmar.pretty(true); + StringBuilderWriter sbw = new StringBuilderWriter(1024); + + + LargerData ld; + Trans trans; + Report report = new Report(ITERATIONS,"XML"); + do { + sbw.reset(); + trans = EnvFactory.newTrans(); + TimeTaken all = trans.start("Combo", Env.SUB); + try { + TimeTaken tt = trans.start("JAXB Unmarshal", Env.XML); + try { + ld = jaxbUmar.unmarshal(LogTarget.NULL, xml); + } finally { + tt.done(); + } + tt = trans.start("JAXB marshal", Env.XML); + try { + jaxBmar.marshal(LogTarget.NULL, ld, sbw); + } finally { + tt.done(); + } + } finally { + all.done(); + } + report.glean(trans,Env.XML); + } while(report.go()); + + report.report(sbw); + System.out.println(sbw.toString()); + } + } + @Test + public void xml2jaxb2xml() throws Exception { + System.out.println("*** XML -> JAXB Object -> XML ***"); + JAXBumar jaxbUmar = new JAXBumar(LargerData.class); + JAXBmar jaxBmar = new JAXBmar(LargerData.class); + //jaxBmar.asFragment(true); + //jaxBmar.pretty(true); + StringBuilderWriter sbw = new StringBuilderWriter(1024); + + LargerData ld; + Trans trans; + Report report = new Report(ITERATIONS,"XML"); + do { + sbw.reset(); + trans = EnvFactory.newTrans(); + TimeTaken all = trans.start("Combo", Env.SUB); + try { + TimeTaken tt = trans.start("JAXB Unmarshal", Env.XML); + try { + ld = jaxbUmar.unmarshal(LogTarget.NULL, xml); + } finally { + tt.done(); + } + tt = trans.start("JAXB marshal", Env.XML); + try { + jaxBmar.marshal(LogTarget.NULL, ld, sbw); + } finally { + tt.done(); + } + } finally { + all.done(); + } + report.glean(trans,Env.XML); + } while(report.go()); + + report.report(sbw); + System.out.println(sbw.toString()); } + + @Test + public void xml2jaxb2PrettyXml() throws Exception { + System.out.println("*** XML -> JAXB Object -> Pretty XML ***"); + JAXBumar jaxbUmar = new JAXBumar(LargerData.class); + JAXBmar jaxBmar = new JAXBmar(LargerData.class); + //jaxBmar.asFragment(true); + jaxBmar.pretty(true); + StringBuilderWriter sbw = new StringBuilderWriter(1024); + + Trans trans = EnvFactory.newTrans(); + LargerData ld; + for(int i=0;i20) { + m = trans.auditTrail(0,null); + } else { + m = trans.auditTrail(0, sbw.getBuffer()); + System.out.println(sbw.getBuffer()); + } + System.out.println(ITERATIONS + " entries, Total Time: " + m.total + "ms, Avg Time: " + m.total/ITERATIONS + "ms"); + } + +} diff --git a/rosetta/src/test/java/com/data/test/JU_JSON.java b/rosetta/src/test/java/com/data/test/JU_JSON.java new file mode 100644 index 0000000..9b1d715 --- /dev/null +++ b/rosetta/src/test/java/com/data/test/JU_JSON.java @@ -0,0 +1,138 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.data.test; + +import java.io.IOException; +import java.io.Reader; +import java.io.StringReader; +import java.io.StringWriter; + +import org.junit.Test; + +import com.att.rosetta.InJson; +import com.att.rosetta.Out; +import com.att.rosetta.OutJson; +import com.att.rosetta.OutRaw; +import com.att.rosetta.Parse; +import com.att.rosetta.ParseException; + +import junit.framework.Assert; + +public class JU_JSON { + + @Test + public void test() throws IOException, ParseException { + InJson jin = new InJson(); + Out jout = new OutJson(); + + go(jin, jout, "{\"id\":\"Me, Myself\",\"date\":1353094689100}"); + + go(jin, jout, "{\"id\":\"My ID 1\",\"desc\":\"My Description 1\",\"comment\":[\"My Comment 1\"],\"utc\":1360418381310}"); + go(jin, jout, "{\"id\":\"My ID 1\",\"desc\":\"My Description 1\",\"comment\":[\"My Comment 1\",\"My Comment 2\"],\"utc\":1360418381310}"); + + go(jin, jout, "{\"SampleData\":[" + + "{\"id\":\"sd object \\\"1\\\"\",\"date\":1316084944213,\"item\":[\"Item 1.1\",\"Item 1.2\"]}," + + "{\"id\":\"sd object \\\"2\\\"\",\"date\":1316084945343,\"item\":[\"Item 2.1\",\"Item 2.2\"]}],\"fluff\":\"MyFluff\"}" + ); + + go(jin, jout, "{\"SampleData\":[{\"date\":1316084945343}],\"fluff\":\"MyFluff\"}"); + + go(jin, jout, "{\"id\":\"Me,[}[eg[)(:x,\\\" Myself\",\"date\":1353094689100}"); + + go(jin,jout, "{\"userid\":\"ab1234\",\"timestamp\":1353097388531,\"item\":[{\"tag\":\"color\",\"value\":\"Mauve\"},{\"tag\":\"shirtsize\",\"value\":\"Xtra Large\"}]}"); + //go() + //"ab12341353082669667"); + + // 3/11/2015 jcg found a case with missing comma + go(jin,jout, "{\"start\":\"2015-03-11T18:18:05.580-05:00\",\"end\":\"2015-09-11-05:00\",\"force\":\"false\",\"perm\":{\"type\":\"com.att.myns.mytype\",\"instance\":\"myInstance\",\"action\":\"myAction\"}" + + ",\"role\":\"com.att.myns.myrole\"}"); + + // 3/12/2015 jcg Kurt Schurenberg noticed an issue of object names in an array. This is valid code. + go(jin,jout, "{\"role\":[{\"name\":\"com.att.myns.myrole\",\"perms\":[{\"type\":\"com.att.myns.mytype\",\"instance\":\"myAction\"},{\"type\":\"com.att.myns.mytype\",\"instance\":\"myOtherAction\"}]}" + + ",{\"name\":\"com.att.myns.myOtherRole\",\"perms\":[{\"type\":\"com.att.myns.myOtherType\",\"instance\":\"myAction\"},{\"type\":\"com.att.myns.myOthertype\",\"instance\":\"myOtherAction\"}]}]}"); + + // 3/13/2015 - discovered with complex Response + go(jin,jout, "{\"meth\":\"GET\",\"path\":\"/authz/perms/:type\",\"desc\":\"GetPermsByType\",\"comments\":[\"List All Permissions that match :type listed\"]," + + "\"contentType\":[\"application/Permissions+json;q=1.0;charset=utf-8;version=1.1,application/json;q=1.0;version=1.1\"" + + ",\"application/Perms+xml;q=1.0;charset=utf-8;version=2.0,text/xml;q=1.0;version=2.0\",\"application/Perms+json;q=1.0;charset=utf-8;version=2.0,application/json;q=1.0;version=2.0,*/*;q=1.0\"" + + ",\"application/Permissions+xml;q=1.0;charset=utf-8;version=1.1,text/xml;q=1.0;version=1.1\"]}"); + + + // Test a Windoze "Pretty Print", validate skipping of Windoze characters as well as other odd control characters listed + // in json.org + StringWriter sw = new StringWriter(); + jout.extract(new StringReader( + "{\b\f\n\r\t \"id\"" + + ":\"Me, \b\f\n\r\tMyself\",\"date\":1353094689100" + + "\b\f\n\r\t }" + ),sw,jin); + Assert.assertEquals("{\"id\":\"Me, \b\f\n\r\tMyself\",\"date\":1353094689100}",sw.toString()); + System.out.println(sw.toString()); + + // 10/01/2015 jcg AAF-703 Ron Gallagher, this response is ok + go(jin,jout, "{\"perm\":[{\"type\":\"com.att.myns.myPerm\",\"action\":\"myAction\",\"description\":\"something\"}]}"); + // but when description:"" causes extra comma at end + go(jin,jout, "{\"perm\":[{\"type\":\"com.att.myns.myPerm\",\"action\":\"myAction\",\"description\":\"\"}]}","{\"perm\":[{\"type\":\"com.att.myns.myPerm\",\"action\":\"myAction\"}]}"); + // Test other empty string scenarios + go(jin,jout, "{\"perm\":[{\"type\":\"\",\"action\":\"\",\"description\":\"\"}]}","{\"perm\":[{}]}"); + go(jin,jout, "{\"perm\":[{\"type\":\"\",\"action\":\"\",\"description\":\"hi\"}]}","{\"perm\":[{\"description\":\"hi\"}]}"); + go(jin,jout, "{\"perm\":[{\"type\":\"\",\"action\":\"myAction\",\"description\":\"\"}]}","{\"perm\":[{\"action\":\"myAction\"}]}"); + + + go(jin,jout, "{\"perm\":[{\"type\":\"com.att.myns.myPerm\",\"action\":,\"description\":\"something\"}]}","{\"perm\":[{\"type\":\"com.att.myns.myPerm\",\"description\":\"something\"}]}"); + + go(jin, jout, "{\"name\":\"\\\"hello\\\"\"}"); + + go(jin, jout, "{\"name\":\"\\\\\"}"); + + go(jin, jout, "{\"role\":\"com.att.scamper.UserStory0152 7_IT-00323-a-admin\",\"perm\":{\"type\":\"com.att.scamper.application\",\"instance\":\"_()`!@#\\\\$%^=+][{}<>/.-valid.app.name-is_good\",\"action\":\"Administrator\"}}"); + + + } + + + private void go(Parse in, Out out, String str) throws IOException, ParseException { + go(in,out,str,str); + } + + + private void go(Parse in, Out out, String str, String cmp) throws IOException, ParseException { + + System.out.println(str); + StringWriter sw = new StringWriter(1024); + out.extract(new StringReader(str), sw, in); + System.out.println(sw); + String result = sw.toString(); + + if(!result.equals(cmp)) { + sw.getBuffer().setLength(0); + new OutRaw().extract(new StringReader(str), sw, in); + System.out.println(sw); + } + + Assert.assertEquals(cmp,result); + System.out.println(); + + } +} diff --git a/rosetta/src/test/java/com/data/test/JU_Ladder.java b/rosetta/src/test/java/com/data/test/JU_Ladder.java new file mode 100644 index 0000000..78d6a10 --- /dev/null +++ b/rosetta/src/test/java/com/data/test/JU_Ladder.java @@ -0,0 +1,80 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.data.test; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import static org.junit.Assert.*; + +import com.att.rosetta.Ladder; + +public class JU_Ladder { + + @Test + public void test() { + Ladder ladder = new Ladder(); + + for(int i=0;i<30;++i) { + for(int j=0;j df = env.newDataFactory(LargerData.class); + df.out(Data.TYPE.JSON); + LargerData urr = new LargerData(); + SampleData sd = new SampleData(); + sd.setDate(1444125487798L); + sd.setId(null); + urr.getSampleData().add(sd); + urr.setFluff(null); + RosettaData data = df.newData(); +// StringWriter sw = new StringWriter(); +// df.direct(trans, urr, sw); +// System.out.println(sw.toString()); + data.load(urr); + System.out.println(data.asString()); + Assert.assertEquals("{\"SampleData\":[{\"date\":1444125487798}]}", data.asString()); + + System.out.println(data.out(Data.TYPE.RAW).asString()); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + } + +} diff --git a/rosetta/src/test/java/com/data/test/JU_RosettaDF.java b/rosetta/src/test/java/com/data/test/JU_RosettaDF.java new file mode 100644 index 0000000..90342b4 --- /dev/null +++ b/rosetta/src/test/java/com/data/test/JU_RosettaDF.java @@ -0,0 +1,165 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.data.test; + +import java.io.StringReader; + +import org.junit.Assert; +import org.junit.Test; + +import com.att.inno.env.Data; +import com.att.inno.env.Data.TYPE; +import com.att.inno.env.TimeTaken; +import com.att.inno.env.Trans; +import com.att.inno.env.impl.EnvFactory; +import com.att.inno.env.jaxb.JAXBmar; +import com.att.inno.env.util.StringBuilderWriter; +import com.att.rosetta.env.RosettaDF; +import com.att.rosetta.env.RosettaData; +import com.att.rosetta.env.RosettaEnv; + +import s.xsd.LargerData; +import s.xsd.Multi; +import s.xsd.SampleData; + +public class JU_RosettaDF { + public static int ITERATIONS = 1; + + @Test + public void testCached() throws Exception { + RosettaEnv env = new RosettaEnv(); + RosettaDF df = env.newDataFactory(LargerData.class); + JAXBmar jmar = new JAXBmar(LargerData.class); + + StringBuilderWriter sbw = new StringBuilderWriter(1024); + Trans trans = EnvFactory.newTrans(); + + Report report = new Report(ITERATIONS,"Load JSON","Extract JAXB", "JAXB Marshal", "Cached to XML", "Cached to JSON"); + do { + sbw.reset(); + trans = EnvFactory.newTrans(); + Data data; + TimeTaken tt = trans.start("Load JSON", 1); + try { + data = df.newData(trans).out(Data.TYPE.JSON).in(Data.TYPE.JSON).load(JU_FromJSON.str); + } finally { + tt.done(); + } + LargerData ld; + tt = trans.start("Extract JAXB", 2); + try { + ld = data.asObject(); + } finally { + tt.done(); + } + + tt = trans.start("JAXB marshal", 3); + try { + jmar.marshal(trans.debug(), ld, sbw); + } finally { + tt.done(); + } + sbw.append('\n'); + + tt = trans.start("To XML from Cache",4); + try { + data.out(Data.TYPE.XML).to(sbw); + } finally { + tt.done(); + } + + sbw.append('\n'); + + tt = trans.start("To JSON from Cache",5); + try { + data.out(Data.TYPE.JSON).to(sbw); + } finally { + tt.done(); + } + report.glean(trans, 1,2,3,4,5); + } while(report.go()); + + report.report(sbw); + System.out.println(sbw); + + } + + @Test + public void testDirect() throws Exception { + RosettaEnv env = new RosettaEnv(); + RosettaDF df = env.newDataFactory(LargerData.class); + + StringBuilderWriter sbw = new StringBuilderWriter(1024); + Trans trans = EnvFactory.newTrans(); + + Report report = new Report(ITERATIONS); + do { + sbw.reset(); + trans = EnvFactory.newTrans(); + RosettaData data = df.newData(trans).in(Data.TYPE.JSON).out(Data.TYPE.XML); + data.direct(new StringReader(JU_FromJSON.str), sbw); + report.glean(trans); + } while(report.go()); + + report.report(sbw); + System.out.println(sbw); + + } + + @Test + public void testMulti() throws Exception { + RosettaEnv env = new RosettaEnv(); + RosettaDF df = env.newDataFactory(Multi.class); + +// StringBuilderWriter sbw = new StringBuilderWriter(1024); +// Trans trans = EnvFactory.newTrans(); + + Multi m = new Multi(); + m.getF1().add("String1"); + m.getF2().add("String2"); + + System.out.println(df.newData().load(m).out(TYPE.RAW).asString()); + System.out.println(df.newData().load(m).out(TYPE.JSON).asString()); + + } + + @Test + public void testQuotes() throws Exception { + RosettaEnv env = new RosettaEnv(); + RosettaDF df = env.newDataFactory(SampleData.class); + + SampleData sd = new SampleData(); + sd.setId("\"AT&T Services, Inc.\""); + System.out.println(sd.getId()); + String out =df.newData().load(sd).out(TYPE.JSON).asString(); + System.out.println(out); + Assert.assertEquals( + "{\"id\":\"\\\"AT&T Services, Inc.\\\"\",\"date\":0}", + out); + + SampleData sd2 = df.newData().in(TYPE.JSON).load(out).asObject(); + System.out.println(sd2.getId()); + Assert.assertEquals(sd.getId(),sd2.getId()); + } +} diff --git a/rosetta/src/test/java/com/data/test/JU_Saved.java b/rosetta/src/test/java/com/data/test/JU_Saved.java new file mode 100644 index 0000000..220bdf7 --- /dev/null +++ b/rosetta/src/test/java/com/data/test/JU_Saved.java @@ -0,0 +1,107 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.data.test; + +import java.io.Reader; +import java.io.StringReader; + +import org.junit.Test; + +import com.att.inno.env.TimeTaken; +import com.att.inno.env.Trans; +import com.att.inno.env.impl.EnvFactory; +import com.att.inno.env.util.StringBuilderWriter; +import com.att.rosetta.InJson; +import com.att.rosetta.JaxInfo; +import com.att.rosetta.OutJson; +import com.att.rosetta.OutXML; +import com.att.rosetta.Saved; + +import s.xsd.LargerData; + +public class JU_Saved { + private static int ITERATIONS = 100000; + + @Test + public void test() throws Exception { + InJson inJSON = new InJson(); + OutDump dump = new OutDump(); + JaxInfo ji = JaxInfo.build(LargerData.class); + OutXML xml = new OutXML(ji);; + OutJson json = new OutJson(); + + Saved saved = new Saved(); + + StringBuilderWriter sbw = new StringBuilderWriter(1024); + + Trans trans; + Report report = new Report(ITERATIONS,"Save","Dump","XML ","JSON"); + do { + sbw.reset(); + trans = EnvFactory.newTrans(); + Reader sr = new StringReader(JU_FromJSON.str); + TimeTaken tt = trans.start("Parse Text, and Save", 1); + try { + saved.load(sr, inJSON); + } finally { + tt.done(); + } + +// sbw.append("==== Start Direct Raw =====\n"); +// new OutRaw().extract(new StringReader(JU_FromJSON.str), sbw, inJSON); +// +// sbw.append("==== Start Raw from Saved =====\n"); +// new OutRaw().extract(null,sbw,saved); + + sbw.append("==== Start Dump from Saved =====\n"); + tt = trans.start("Dump", 2); + try { + dump.extract(null,sbw,saved); + } finally { + tt.done(); + } + + sbw.append("\n==== Start XML =====\n"); + tt = trans.start("XML", 3); + try { + xml.extract(null,sbw,saved); + } finally { + tt.done(); + } + + sbw.append("\n==== Start JSON =====\n"); + tt = trans.start("JSON", 4); + try { + json.extract(null,sbw,saved); + } finally { + tt.done(); + } + report.glean(trans,1,2,3,4); + } while(report.go()); + + report.report(sbw); + System.out.println(sbw.toString()); + + } +} diff --git a/rosetta/src/test/java/com/data/test/JU_Stream2Obj.java b/rosetta/src/test/java/com/data/test/JU_Stream2Obj.java new file mode 100644 index 0000000..c714b57 --- /dev/null +++ b/rosetta/src/test/java/com/data/test/JU_Stream2Obj.java @@ -0,0 +1,126 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.data.test; + +import java.io.IOException; +import java.io.Reader; +import java.io.StringReader; +import java.io.StringWriter; + +import org.junit.Test; + +import com.att.inno.env.APIException; +import com.att.inno.env.Data; +import com.att.inno.env.DataFactory; +import com.att.inno.env.EnvJAXB; +import com.att.inno.env.impl.BasicEnv; +import com.att.rosetta.InJson; +import com.att.rosetta.InXML; +import com.att.rosetta.Out; +import com.att.rosetta.OutJson; +import com.att.rosetta.OutRaw; +import com.att.rosetta.OutXML; +import com.att.rosetta.Parse; +import com.att.rosetta.ParseException; + +import inherit.DerivedA; +import inherit.Root; + +public class JU_Stream2Obj { + + /* + + + + myDerivedA_1 + 1432 + mda_1 + value_1 + value_2 + + + + {"base":[{"__extension":"derivedA","name":"myDerivedA_1","num":1432,"shortName":"mda_1","value":["value_1","value_2"]}]} + */ + + @Test + public void json2Obj() throws APIException, SecurityException, NoSuchFieldException, ClassNotFoundException, ParseException, IOException { + DerivedA da = new DerivedA(); + da.setName("myDerivedA_1"); + da.setNum((short)1432); + da.setShortName("mda_1"); + da.getValue().add("value_1"); + da.getValue().add("value_2"); + + Root root = new Root(); + root.getBase().add(da); + + da = new DerivedA(); + da.setName("myDerivedA_2"); + da.setNum((short)1432); + da.setShortName("mda_2"); + da.getValue().add("value_2.1"); + da.getValue().add("value_2.2"); + root.getBase().add(da); + + EnvJAXB env = new BasicEnv(); + DataFactory rootDF = env.newDataFactory(Root.class); + + String xml = rootDF.newData(env).out(Data.TYPE.XML).load(root).option(Data.PRETTY).asString(); + System.out.println(xml); + + InXML inXML; + Parse in = inXML = new InXML(Root.class); + Out out = new OutRaw(); + + StringWriter sw = new StringWriter(); + out.extract(new StringReader(xml), sw, in); + System.out.println(sw.toString()); + + + out = new OutJson(); + + sw = new StringWriter(); + out.extract(new StringReader(xml), sw, in); + String json; + System.out.println(json = sw.toString()); + + in = new InJson(); + out = new OutRaw(); + + sw = new StringWriter(); + out.extract(new StringReader(json), sw, in); + System.out.println(sw.toString()); + + out = new OutXML(inXML); + + sw = new StringWriter(); + out.extract(new StringReader(json), sw, in, true); + System.out.println(sw.toString()); + + System.out.flush(); + + } + +} diff --git a/rosetta/src/test/java/com/data/test/JU_Struct.java b/rosetta/src/test/java/com/data/test/JU_Struct.java new file mode 100644 index 0000000..1d1ee96 --- /dev/null +++ b/rosetta/src/test/java/com/data/test/JU_Struct.java @@ -0,0 +1,76 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.data.test; + +import org.junit.Test; + +import com.att.rosetta.JaxInfo; + +import s.xsd.LargerData; + +public class JU_Struct { + public final static String XML ="\n" + + "\n" + + "sd object 1\n" + + "1346439215932\n" + + "Item 1.1\n" + + "Item 1.2\n" + + "\n" + + "\n" + + "sd object 2\n" + + "1346439215932\n" + + "Item 2.1\n" + + "Item 2.2\n" + + "\n" + + "MyFluff\n" + + "\n"; + +// @Test +// public void test2() throws Exception { +// +// SampleData sd = new SampleData(); +// sd.setDate(new Date().getTime()); +// sd.setId("myId"); +// sd.getItem().add("Item 1.1"); +// +// InObj inObj = new InObj(SampleData.class); +// +// JaxSet jaxSet = JaxSet.get(SampleData.class); +// Setter setter = jaxSet.setter("id"); +// setter.set(sd, "Your ID"); +// +// for(Entry> es : jaxSet.getters()) { +// System.out.print(es.getKey()); +// System.out.print(' '); +// System.out.println(es.getValue().get(sd)); +// } +// } + + @Test + public void test() throws Exception { + JaxInfo ji = JaxInfo.build(LargerData.class); + System.out.println(ji); + } + +} diff --git a/rosetta/src/test/java/com/data/test/JU_Types.java b/rosetta/src/test/java/com/data/test/JU_Types.java new file mode 100644 index 0000000..02f5ac3 --- /dev/null +++ b/rosetta/src/test/java/com/data/test/JU_Types.java @@ -0,0 +1,304 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.data.test; + +import java.io.StringWriter; + +import javax.xml.datatype.XMLGregorianCalendar; +import javax.xml.namespace.QName; + +import org.junit.Test; + +import com.att.inno.env.Data; +import com.att.inno.env.Data.TYPE; +import com.att.inno.env.Env; +import com.att.inno.env.Trans; +import com.att.inno.env.Trans.Metric; +import com.att.inno.env.jaxb.JAXBmar; +import com.att.inno.env.jaxb.JAXBumar; +import com.att.inno.env.util.Chrono; +import com.att.inno.env.util.StringBuilderWriter; +import com.att.rosetta.OutJson; +import com.att.rosetta.OutRaw; +import com.att.rosetta.OutXML; +import com.att.rosetta.env.RosettaDF; +import com.att.rosetta.env.RosettaData; +import com.att.rosetta.env.RosettaEnv; +import com.att.rosetta.marshal.DocMarshal; +import com.data.test.obj.MultiMarshal; +import com.data.test.obj.SingleMarshal; + +import types.xsd.Multi; +import types.xsd.Multi.Single; + +public class JU_Types { + + @Test + public void single() throws Exception { + Single single = setSData(); + SingleMarshal psingle = new SingleMarshal(); + + OutRaw raw = new OutRaw(); + OutJson json = new OutJson(); + OutXML xml = new OutXML("Single","xmlns=urn:types:xsd"); + + + System.out.println("===== RAW ====="); + raw.extract(single, System.out, psingle); + + System.out.println("\n===== JSON ====="); + json.extract(single, System.out, psingle); + + System.out.println("\n\n===== Pretty JSON ====="); + json.extract(single, System.out, psingle, true); + + System.out.println("\n\n===== XML ====="); + xml.extract(single, System.out, psingle,false); + + System.out.println("\n\n===== Pretty XML ====="); + xml.extract(single, System.out, psingle, true); + + RosettaEnv env = new RosettaEnv(); + StringWriter sw = new StringWriter(); + xml.extract(single, sw, psingle, true); + JAXBumar jumar = new JAXBumar(single.getClass()); + JAXBmar jmar = new JAXBmar(new QName("Single","urn.types.xsd"),single.getClass()); + jmar.pretty(true); + sw = new StringWriter(); + jmar.marshal(env.info(), single, sw); + System.out.println(sw); + Single news = jumar.unmarshal(env.info(), sw.toString()); +// System.out.println(news.getDatetime()); +// sw = new StringWriter(); +// news.setDatetime(Chrono.timeStamp()); +// xml.extract(single, sw, psingle, true); + news = jumar.unmarshal(env.info(), sw.toString()); + System.out.println(sw.toString()); + + String sample = "" + + "\n" + + "\nMyString" + + "\n2147483647" + + "\n9223372036854775807" + + "\n2015-05-27-05:00" + + "\n2015-05-27T07:05:04.234-05:00" + + "\nFF00FF0E082507807F" + + "\nString 1" + + "\nString 2" + + "\n"; + System.out.println(sample); + news = jumar.unmarshal(env.info(), sample); + + System.out.println(news.getDatetime()); + + } + + @Test + public void multi() throws Exception { + OutRaw raw = new OutRaw(); + OutJson json = new OutJson(); + OutXML xml = new OutXML("Multi","xmlns=urn:types:xsd"); + + Multi multi = new Multi(); + MultiMarshal pmulti = new MultiMarshal(); + + for(int i=0;i<10;++i) { + System.out.println("===== Multi Iteration " + i + " ====="); + if(i>0) { + multi.getSingle().add(setSData()); + } + System.out.println(" ===== RAW ====="); + raw.extract(multi, System.out, pmulti); + + System.out.println("\n ===== JSON ====="); + json.extract(multi, System.out, pmulti); + + System.out.println("\n\n ===== Pretty JSON ====="); + json.extract(multi, System.out, pmulti, true); + + System.out.println("\n\n ===== XML ====="); + xml.extract(multi, System.out, pmulti,false); + + System.out.println("\n\n ===== Pretty XML ====="); + xml.extract(multi, System.out, pmulti, true); + } + } + + @Test + public void doc() throws Exception { + OutRaw raw = new OutRaw(); + OutJson json = new OutJson(); + OutXML xml = new OutXML("Multi","xmlns=urn:types:xsd"); + + Multi multi = new Multi(); + DocMarshal doc = DocMarshal.root(new MultiMarshal()); + + for(int i=0;i<3;++i) { + System.out.println("===== Multi Iteration " + i + " ====="); + if(i>0) { + multi.getSingle().add(setSData()); + } + System.out.println(" ===== RAW ====="); + raw.extract(multi, System.out, doc); + + System.out.println("\n ===== JSON ====="); + json.extract(multi, System.out, doc); + + System.out.println("\n\n ===== Pretty JSON ====="); + json.extract(multi, System.out, doc, true); + + System.out.println("\n\n ===== XML ====="); + xml.extract(multi, System.out, doc,false); + + System.out.println("\n\n ===== Pretty XML ====="); + xml.extract(multi, System.out, doc, true); + } + } + + +// @Test +// public void saved() throws Exception { +// Saved saved = new Saved(); +// saved.extract(in, ignore, parser, options); +// } + + @Test + public void df() throws Exception { + RosettaEnv env = new RosettaEnv(); + RosettaDF df = env.newDataFactory(Multi.class); + df.out(TYPE.JSON).option(Data.PRETTY); + + Multi multi = new Multi(); + multi.getSingle().add(setSData()); + + + System.out.println("========== Original loading"); + Trans trans = env.newTrans(); + RosettaData data = df.newData(trans); + // Prime pump + for(int i=0;i<100;++i) { + data.load(multi); + } + trans = env.newTrans(); + data = df.newData(trans); + + int iters = 10000; + for(int i=0;i jin = new InJson(); +// Out jout = new OutJson(); +// +//// go(jin, jout, "{\"id\":\"Me, Myself\",\"date\":1353094689100}"); +// +// } + + + /* + private void go(Parse in, Out out, String str) throws IOException, ParseException { + + System.out.println(str); + StringWriter sw = new StringWriter(1024); + out.extract(new StringReader(str), sw, in); + System.out.println(sw); + String result = sw.toString(); + + if(!result.equals(str)) { + sw.getBuffer().setLength(0); + new OutRaw().extract(new StringReader(str), sw, in); + System.out.println(sw); + } + + Assert.assertEquals(str,result); + System.out.println(); + + } + */ +} diff --git a/rosetta/src/test/java/com/data/test/OutDump.java b/rosetta/src/test/java/com/data/test/OutDump.java new file mode 100644 index 0000000..cd65e15 --- /dev/null +++ b/rosetta/src/test/java/com/data/test/OutDump.java @@ -0,0 +1,93 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.data.test; + +import java.io.IOException; +import java.io.Writer; + +import com.att.inno.env.util.IndentPrintWriter; +import com.att.rosetta.Out; +import com.att.rosetta.Parse; +import com.att.rosetta.ParseException; +import com.att.rosetta.Parsed; + +public class OutDump extends Out{ + + @Override + public void extract(IN in, Writer writer, Parse prs, boolean ... options) throws IOException, ParseException { + IndentPrintWriter ipw = writer instanceof IndentPrintWriter?(IndentPrintWriter)writer:new IndentPrintWriter(writer); + + Parsed p = prs.newParsed(); + + while((p = prs.parse(in,p.reuse())).valid()) { + switch(p.event) { + case Parse.START_OBJ: + ipw.append("Start Object "); + ipw.append(p.name); + ipw.inc(); + break; + case Parse.END_OBJ: + printData(ipw,p); + ipw.dec(); + ipw.append("End Object "); + ipw.append(p.name); + break; + case Parse.START_ARRAY: + ipw.inc(); + ipw.append("Start Array "); + ipw.append(p.name); + ipw.append('\n'); + break; + case Parse.END_ARRAY: + printData(ipw,p); + ipw.dec(); + ipw.append("End Array "); + ipw.append('\n'); + break; + case Parse.NEXT: + printData(ipw,p); + break; + } + } + } + + private void printData(IndentPrintWriter ipw, Parsed parsed) { + if(parsed.hasData()) { + ipw.append("Data:["); + if(parsed.hasName()) { + ipw.append(parsed.name); + ipw.append(" : "); + } + ipw.append(parsed.sb); + ipw.append("]"); + ipw.append('\n'); + } + } + + @Override + public String logName() { + return "Rosetta OutDump"; + } + +} diff --git a/rosetta/src/test/java/com/data/test/Report.java b/rosetta/src/test/java/com/data/test/Report.java new file mode 100644 index 0000000..d05443a --- /dev/null +++ b/rosetta/src/test/java/com/data/test/Report.java @@ -0,0 +1,69 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.data.test; + +import java.io.IOException; +import java.io.Writer; + +import com.att.inno.env.Trans; +import com.att.inno.env.Trans.Metric; + +public class Report { + float total; + float buckets[]; + String[] names; + private int iterations; + private int count; + + public Report(int iters, String ... names) { + iterations = iters; + buckets = new float[names.length]; + this.names = names; + total=0; + count = 0; + } + + public void glean(Trans trans, int ... type) { + Metric m = trans.auditTrail(0, null, type); + total+=m.total; + int min = Math.min(buckets.length, m.buckets.length); + for(int b=0;b { + public MultiMarshal() { + add(new ObjArray("single",new SingleMarshal()) { + @Override + protected List data(Multi t) { + return t.getSingle(); + } + }); + } +} diff --git a/rosetta/src/test/java/com/data/test/obj/SingleMarshal.java b/rosetta/src/test/java/com/data/test/obj/SingleMarshal.java new file mode 100644 index 0000000..1546622 --- /dev/null +++ b/rosetta/src/test/java/com/data/test/obj/SingleMarshal.java @@ -0,0 +1,93 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aai + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * Copyright © 2017 Amdocs + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package com.data.test.obj; + +import java.util.List; + +import javax.xml.datatype.XMLGregorianCalendar; + +import com.att.rosetta.marshal.DataWriter; +import com.att.rosetta.marshal.FieldArray; +import com.att.rosetta.marshal.FieldDate; +import com.att.rosetta.marshal.FieldDateTime; +import com.att.rosetta.marshal.FieldHexBinary; +import com.att.rosetta.marshal.FieldNumeric; +import com.att.rosetta.marshal.FieldString; +import com.att.rosetta.marshal.ObjMarshal; + +import types.xsd.Multi.Single; + +public class SingleMarshal extends ObjMarshal { + public SingleMarshal() { + add(new FieldString("str") { + @Override + protected String data(Single t) { + return t.getStr(); + } + }); + + add(new FieldNumeric("int") { + @Override + protected Integer data(Single t) { + return t.getInt(); + } + }); + + add(new FieldNumeric("long") { + @Override + protected Long data(Single t) { + return t.getLong(); + } + }); + + add(new FieldDate("date") { + @Override + protected XMLGregorianCalendar data(Single t) { + return t.getDate(); + } + }); + + add(new FieldDateTime("datetime") { + @Override + protected XMLGregorianCalendar data(Single t) { + return t.getDate(); + } + }); + + add(new FieldHexBinary("binary") { + @Override + protected byte[] data(Single t) { + return t.getBinary(); + } + }); + + add(new FieldArray("array", DataWriter.STRING) { + @Override + protected List data(Single t) { + return t.getArray(); + } + }); + + } +} -- cgit 1.2.3-korg