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;
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();
44 data.delegate = "yourname";
45 data.expires = new Date();
48 ByteBuffer bb = data.bytify();
49 Data bdata = new DelegateDAO.Data();
50 bdata.reconstitute(bb);
55 Result<Data> ddcr = dao.create(trans,data);
56 assertTrue(ddcr.isOK());
60 Result<List<DelegateDAO.Data>> records = dao.read(trans,data.user);
61 assertTrue(records.isOKhasData());
62 for(DelegateDAO.Data rdata : records.value)
66 records = dao.readByDelegate(trans,data.delegate);
67 assertTrue(records.isOKhasData());
68 for(DelegateDAO.Data rdata : records.value)
72 data.delegate = "hisname";
73 data.expires = new Date();
74 assertTrue(dao.update(trans, data).isOK());
77 records = dao.read(trans,data.user);
78 assertTrue(records.isOKhasData());
79 for(DelegateDAO.Data rdata : records.value)
83 records = dao.readByDelegate(trans,data.delegate);
84 assertTrue(records.isOKhasData());
85 for(DelegateDAO.Data rdata : records.value)
89 dao.delete(trans,data, true);
90 records = dao.read(trans,data.user);
91 assertTrue(records.isEmpty());
99 private void compare(Data d1, Data d2) {
100 assertEquals(d1.user, d2.user);
101 assertEquals(d1.delegate, d2.delegate);
102 assertEquals(d1.expires,d2.expires);