2 * ============LICENSE_START====================================================
4 * ===========================================================================
5 * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
6 * ===========================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END====================================================
22 package org.onap.aaf.cadi.aaf.marshal.test;
24 import static org.junit.Assert.*;
25 import static org.hamcrest.CoreMatchers.*;
27 import java.io.ByteArrayOutputStream;
28 import java.io.IOException;
29 import java.io.PrintStream;
31 import javax.xml.datatype.XMLGregorianCalendar;
35 import org.onap.aaf.cadi.aaf.marshal.CertMarshal;
36 import org.onap.aaf.misc.env.util.Chrono;
37 import org.onap.aaf.misc.rosetta.OutRaw;
38 import org.onap.aaf.misc.rosetta.ParseException;
39 import org.onap.aaf.misc.rosetta.marshal.DataWriter;
41 import aaf.v2_0.Certs.Cert;
43 public class JU_CertMarshal {
45 private static final String fingerprint = "fingerprint";
46 private static final String id = "id";
47 private static final String x500 = "x500";
49 private String fingerprintAsString;
51 private XMLGregorianCalendar expires;
53 private ByteArrayOutputStream outStream;
57 expires = Chrono.timeStamp();
58 outStream = new ByteArrayOutputStream();
59 StringBuilder sb = new StringBuilder();
60 DataWriter.HEX_BINARY.write(fingerprint.getBytes(), sb);
61 fingerprintAsString = sb.toString();
65 public void test() throws ParseException, IOException {
66 Cert cert = setupCert();
67 CertMarshal cm = new CertMarshal();
68 OutRaw raw = new OutRaw();
70 raw.extract(cert, new PrintStream(outStream), cm);
72 String[] output = outStream.toString().split("\n");
74 String[] expected = new String[] {
76 ", - fingerprint : \"" + fingerprintAsString + "\"",
77 ", - id : \"" + id + "\"",
78 ", - x500 : \"" + x500 + "\"",
79 ", - expires : \"" + Chrono.dateTime(expires) + "\"",
83 assertThat(output.length, is(expected.length));
85 for (int i = 0; i < output.length; i++) {
86 assertThat(output[i], is(expected[i]));
90 private Cert setupCert() {
91 Cert cert = new Cert();
94 cert.setExpires(expires);
95 cert.setFingerprint(fingerprint.getBytes());