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 com.att.dao.aaf.test;
25 import static org.junit.Assert.assertEquals;
26 import static org.junit.Assert.assertTrue;
28 import java.nio.ByteBuffer;
29 import java.util.Date;
30 import java.util.List;
32 import org.junit.Test;
33 import org.onap.aaf.auth.dao.cass.DelegateDAO;
34 import org.onap.aaf.auth.dao.cass.DelegateDAO.Data;
35 import org.onap.aaf.auth.layer.Result;
38 public class JU_DelegateDAO extends AbsJUCass {
40 public void testCRUD() throws Exception {
41 DelegateDAO dao = new DelegateDAO(trans, cluster, AUTHZ);
42 DelegateDAO.Data data = new DelegateDAO.Data();
43 // TODO: Clean out AT&T specific data
45 data.delegate = "rd8227";
46 data.expires = new Date();
49 ByteBuffer bb = data.bytify();
50 Data bdata = new DelegateDAO.Data();
51 bdata.reconstitute(bb);
56 Result<Data> ddcr = dao.create(trans,data);
57 assertTrue(ddcr.isOK());
61 Result<List<DelegateDAO.Data>> records = dao.read(trans,data.user);
62 assertTrue(records.isOKhasData());
63 for(DelegateDAO.Data rdata : records.value)
67 records = dao.readByDelegate(trans,data.delegate);
68 assertTrue(records.isOKhasData());
69 for(DelegateDAO.Data rdata : records.value)
73 // TODO: Clean out AT&T specific data
74 data.delegate = "pf2819";
75 data.expires = new Date();
76 assertTrue(dao.update(trans, data).isOK());
79 records = dao.read(trans,data.user);
80 assertTrue(records.isOKhasData());
81 for(DelegateDAO.Data rdata : records.value)
85 records = dao.readByDelegate(trans,data.delegate);
86 assertTrue(records.isOKhasData());
87 for(DelegateDAO.Data rdata : records.value)
91 dao.delete(trans,data, true);
92 records = dao.read(trans,data.user);
93 assertTrue(records.isEmpty());
101 private void compare(Data d1, Data d2) {
102 assertEquals(d1.user, d2.user);
103 assertEquals(d1.delegate, d2.delegate);
104 assertEquals(d1.expires,d2.expires);