1 /*******************************************************************************
2 * ============LICENSE_START====================================================
4 * * ===========================================================================
5 * * Copyright © 2017 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====================================================
21 ******************************************************************************/
22 package org.onap.aaf.auth.dao.aaf.test;
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertTrue;
27 import java.io.IOException;
28 import java.math.BigInteger;
29 import java.nio.ByteBuffer;
30 import java.security.NoSuchAlgorithmException;
31 import java.util.List;
33 import org.junit.Test;
34 import org.onap.aaf.auth.dao.cass.CertDAO;
35 import org.onap.aaf.auth.dao.cass.CertDAO.Data;
36 import org.onap.aaf.auth.layer.Result;
37 import org.onap.aaf.misc.env.APIException;
44 public class JU_CertDAO extends AbsJUCass {
46 public void test() throws IOException, NoSuchAlgorithmException, APIException {
47 CertDAO cdao = new CertDAO(trans,cluster,"authz");
50 CertDAO.Data data = new CertDAO.Data();
51 data.serial=new BigInteger("11839383");
52 data.id = "m55555@tguard.att.com";
53 data.x500="CN=ju_cert.dao.att.com, OU=AAF, O=\"ATT Services, Inc.\", L=Southfield, ST=Michigan, C=US";
54 data.x509="I'm a cert";
56 cdao.create(trans,data);
59 ByteBuffer bb = data.bytify();
60 Data bdata = new CertDAO.Data();
61 bdata.reconstitute(bb);
62 checkData1(data, bdata);
64 // Validate Read with key fields in Data
65 Result<List<CertDAO.Data>> rlcd = cdao.read(trans,data);
66 assertTrue(rlcd.isOKhasData());
67 for(CertDAO.Data d : rlcd.value) {
71 // Validate Read with key fields in Data
72 rlcd = cdao.read(trans,data.ca,data.serial);
73 assertTrue(rlcd.isOKhasData());
74 for(CertDAO.Data d : rlcd.value) {
79 data.id = "m66666.tguard.att.com";
80 cdao.update(trans,data);
81 rlcd = cdao.read(trans,data);
82 assertTrue(rlcd.isOKhasData());
83 for(CertDAO.Data d : rlcd.value) {
87 cdao.delete(trans,data, true);
95 private void checkData1(Data data, Data d) {
96 assertEquals(data.ca,d.ca);
97 assertEquals(data.serial,d.serial);
98 assertEquals(data.id,d.id);
99 assertEquals(data.x500,d.x500);
100 assertEquals(data.x509,d.x509);