Improve coverage of cadi-aaf 63/45463/1
authorIanHowell <ian.howell@att.com>
Tue, 1 May 2018 15:48:55 +0000 (10:48 -0500)
committerIanHowell <ian.howell@att.com>
Tue, 1 May 2018 15:49:03 +0000 (10:49 -0500)
Issue-ID: AAF-223
Change-Id: I2a7835720341989b45de239157dd1c4f976b1e6a
Signed-off-by: IanHowell <ian.howell@att.com>
cadi/aaf/src/test/java/org/onap/aaf/cadi/aaf/marshal/test/JU_CertMarshal.java [new file with mode: 0644]
cadi/aaf/src/test/java/org/onap/aaf/cadi/aaf/marshal/test/JU_CertsMarshal.java [new file with mode: 0644]
misc/rosetta/src/main/java/org/onap/aaf/misc/rosetta/marshal/ObjArray.java
misc/rosetta/src/main/java/org/onap/aaf/misc/rosetta/marshal/ObjMarshal.java

diff --git a/cadi/aaf/src/test/java/org/onap/aaf/cadi/aaf/marshal/test/JU_CertMarshal.java b/cadi/aaf/src/test/java/org/onap/aaf/cadi/aaf/marshal/test/JU_CertMarshal.java
new file mode 100644 (file)
index 0000000..560014d
--- /dev/null
@@ -0,0 +1,99 @@
+/**
+ * ============LICENSE_START====================================================
+ * org.onap.aaf
+ * ===========================================================================
+ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
+ * ===========================================================================
+ * 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====================================================
+ *
+ */
+
+package org.onap.aaf.cadi.aaf.marshal.test;
+
+import static org.junit.Assert.*;
+import static org.hamcrest.CoreMatchers.*;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.PrintStream;
+
+import javax.xml.datatype.XMLGregorianCalendar;
+
+import org.junit.*;
+
+import org.onap.aaf.cadi.aaf.marshal.CertMarshal;
+import org.onap.aaf.misc.env.util.Chrono;
+import org.onap.aaf.misc.rosetta.OutRaw;
+import org.onap.aaf.misc.rosetta.ParseException;
+import org.onap.aaf.misc.rosetta.marshal.DataWriter;
+
+import aaf.v2_0.Certs.Cert;
+
+public class JU_CertMarshal {
+
+       private static final String fingerprint = "fingerprint";
+       private static final String id = "id";
+       private static final String x500 = "x500";
+
+       private String fingerprintAsString;
+
+       private XMLGregorianCalendar expires;
+
+       private ByteArrayOutputStream outStream;
+
+       @Before
+       public void setup() {
+               expires = Chrono.timeStamp();
+               outStream = new ByteArrayOutputStream();
+               StringBuilder sb = new StringBuilder();
+               DataWriter.HEX_BINARY.write(fingerprint.getBytes(), sb);
+               fingerprintAsString = sb.toString();
+       }
+
+       @Test
+       public void test() throws ParseException, IOException {
+               Cert cert = setupCert();
+               CertMarshal cm = new CertMarshal();
+               OutRaw raw = new OutRaw();
+
+               raw.extract(cert, new PrintStream(outStream), cm);
+
+               String[] output = outStream.toString().split("\n");
+
+               String[] expected = new String[] {
+                               "{ - ",
+                               ", - fingerprint : \"" + fingerprintAsString + "\"",
+                               ", - id : \"" + id + "\"",
+                               ", - x500 : \"" + x500 + "\"",
+                               ", - expires : \"" + Chrono.dateTime(expires) + "\"",
+                               "} - ",
+               };
+
+               assertThat(output.length, is(expected.length));
+
+               for (int i = 0; i < output.length; i++) {
+                       assertThat(output[i], is(expected[i]));
+               }
+       }
+
+       private Cert setupCert() {
+               Cert cert = new Cert();
+               cert.setId(id);
+               cert.setX500(x500);
+               cert.setExpires(expires);
+               cert.setFingerprint(fingerprint.getBytes());
+               return cert;
+       }
+
+}
diff --git a/cadi/aaf/src/test/java/org/onap/aaf/cadi/aaf/marshal/test/JU_CertsMarshal.java b/cadi/aaf/src/test/java/org/onap/aaf/cadi/aaf/marshal/test/JU_CertsMarshal.java
new file mode 100644 (file)
index 0000000..6598fbe
--- /dev/null
@@ -0,0 +1,118 @@
+/**
+ * ============LICENSE_START====================================================
+ * org.onap.aaf
+ * ===========================================================================
+ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
+ * ===========================================================================
+ * 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====================================================
+ *
+ */
+
+package org.onap.aaf.cadi.aaf.marshal.test;
+
+import org.junit.*;
+import static org.hamcrest.CoreMatchers.*;
+import static org.junit.Assert.*;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.PrintStream;
+import java.util.ArrayList;
+
+import javax.xml.datatype.XMLGregorianCalendar;
+import org.onap.aaf.cadi.aaf.marshal.CertsMarshal;
+import org.onap.aaf.misc.env.util.Chrono;
+import org.onap.aaf.misc.rosetta.OutRaw;
+import org.onap.aaf.misc.rosetta.ParseException;
+import org.onap.aaf.misc.rosetta.marshal.DataWriter;
+
+import aaf.v2_0.Certs;
+import aaf.v2_0.Certs.Cert;
+
+public class JU_CertsMarshal {
+
+       private static final String fingerprint = "fingerprint";
+       private static final String id = "id";
+       private static final String x500 = "x500";
+
+       private String fingerprintAsString;
+
+       private XMLGregorianCalendar expires;
+
+       private ByteArrayOutputStream outStream;
+
+       @Before
+       public void setup() {
+               expires = Chrono.timeStamp();
+               outStream = new ByteArrayOutputStream();
+               StringBuilder sb = new StringBuilder();
+               DataWriter.HEX_BINARY.write(fingerprint.getBytes(), sb);
+               fingerprintAsString = sb.toString();
+       }
+
+       @Test
+       public void test() throws ParseException, IOException {
+               CertsStub certs = new CertsStub();
+               CertsMarshal cm = new CertsMarshal();
+               OutRaw raw = new OutRaw();
+
+               raw.extract(certs, new PrintStream(outStream), cm);
+               String[] output = outStream.toString().split("\n");
+
+               String[] expected = new String[] {
+               "{ - ",
+                       "[ - cert",
+                       "{ - ",
+                               ", - fingerprint : \"" + fingerprintAsString + "\"",
+                               ", - id : \"" + id + "\"",
+                               ", - x500 : \"" + x500 + "\"",
+                               ", - expires : \"" + Chrono.dateTime(expires) + "\"",
+                       "} - ",
+                       ", - ",
+                       "{ - ",
+                               ", - fingerprint : \"" + fingerprintAsString + "\"",
+                               ", - id : \"" + id + "\"",
+                               ", - x500 : \"" + x500 + "\"",
+                               ", - expires : \"" + Chrono.dateTime(expires) + "\"",
+                       "} - ",
+                       "] - ",
+                       "} - ",
+               };
+
+               assertThat(output.length, is(expected.length));
+
+               for (int i = 0; i < output.length; i++) {
+                       assertThat(output[i], is(expected[i]));
+               }
+       }
+
+       private Cert setupCert() {
+               Cert cert = new Cert();
+               cert.setId(id);
+               cert.setX500(x500);
+               cert.setExpires(expires);
+               cert.setFingerprint(fingerprint.getBytes());
+               return cert;
+       }
+
+       private class CertsStub extends Certs {
+               public CertsStub() {
+                       cert = new ArrayList<>();
+                       for (int i = 0; i < 2; i++) {
+                               cert.add(setupCert());
+                       }
+               }
+       }
+
+}
index 3d7d1b4..fa95dee 100644 (file)
@@ -53,25 +53,24 @@ public abstract class ObjArray<T,S> extends Marshal<T> {
                                parsed.event = START_ARRAY;
                                parsed.name = name;
                        }
-               } else if (DONE_ITERATOR.equals(iter)) {
-               } else {
+               } else if (!DONE_ITERATOR.equals(iter)) {
                        ladder.ascend(); // look at field info
-                               Iterator<?> memIter = ladder.peek();
-                               ListIterator<S> mems = (ListIterator<S>)iter;
-                               S mem;
-                               if(memIter==null) {
-                                       mem=mems.next();
-                               } else if(!DONE_ITERATOR.equals(memIter)) {
-                                       mem=mems.peek();
-                               } else if(iter.hasNext()) {
-                                       mem=null;
-                                       ladder.push(null);
-                               } else {
-                                       mem=null;
-                               }
-                               
-                               if(mem!=null)
-                                       parsed = subMarshaller.parse(mem, parsed);
+                       Iterator<?> memIter = ladder.peek();
+                       ListIterator<S> mems = (ListIterator<S>)iter;
+                       S mem;
+                       if(memIter==null) {
+                               mem=mems.next();
+                       } else if(!DONE_ITERATOR.equals(memIter)) {
+                               mem=mems.peek();
+                       } else if(iter.hasNext()) {
+                               mem=null;
+                               ladder.push(null);
+                       } else {
+                               mem=null;
+                       }
+
+                       if(mem!=null)
+                               parsed = subMarshaller.parse(mem, parsed);
                        ladder.descend();
                        if(mem==null) {
                                if(iter.hasNext()) {
index 4857293..cb2c478 100644 (file)
@@ -73,26 +73,25 @@ public abstract class ObjMarshal<T> extends Marshal<T> {
                        } else {
                                ladder.push(DONE_ITERATOR);
                        }
-               } else if (DONE_ITERATOR.equals(iter)) {
-               } else {
+               } else if (!DONE_ITERATOR.equals(iter)) {
                        FieldsIterator fields = (FieldsIterator)iter;
                        ladder.ascend(); // look at field info
-                               Iterator<?> currFieldIter = ladder.peek();
-                               Marshal<T> marshal;
-                               if(currFieldIter==null) {
-                                       marshal=fields.next();
-                               } else if(!DONE_ITERATOR.equals(currFieldIter)) {
-                                       marshal=fields.peek();
-                                       if(marshal==null && fields.hasNext())marshal=fields.next();
-                               } else if(fields.hasNext()) {
-                                       marshal=fields.next();
-                                       ladder.push(null);
-                               } else {
-                                       marshal=null;
-                               }
-                               
-                               if(marshal!=null)
-                                       parsed = marshal.parse(in, parsed);
+                       Iterator<?> currFieldIter = ladder.peek();
+                       Marshal<T> marshal;
+                       if(currFieldIter==null) {
+                               marshal=fields.next();
+                       } else if(!DONE_ITERATOR.equals(currFieldIter)) {
+                               marshal=fields.peek();
+                               if(marshal==null && fields.hasNext())marshal=fields.next();
+                       } else if(fields.hasNext()) {
+                               marshal=fields.next();
+                               ladder.push(null);
+                       } else {
+                               marshal=null;
+                       }
+
+                       if(marshal!=null)
+                               parsed = marshal.parse(in, parsed);
                        ladder.descend();
                        if(marshal==null || parsed.event==NONE) {
                                parsed.event = END_OBJ;