1 /*******************************************************************************
\r
2 * ============LICENSE_START====================================================
\r
4 * * ===========================================================================
\r
5 * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
\r
6 * * ===========================================================================
\r
7 * * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * * you may not use this file except in compliance with the License.
\r
9 * * You may obtain a copy of the License at
\r
11 * * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * * Unless required by applicable law or agreed to in writing, software
\r
14 * * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * * See the License for the specific language governing permissions and
\r
17 * * limitations under the License.
\r
18 * * ============LICENSE_END====================================================
\r
20 * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
\r
22 ******************************************************************************/
\r
23 package org.onap.aaf.dao.aaf.test;
\r
26 import static org.junit.Assert.assertEquals;
\r
27 import static org.junit.Assert.assertTrue;
\r
29 import java.nio.ByteBuffer;
\r
30 import java.util.Date;
\r
31 import java.util.List;
\r
33 import org.junit.Test;
\r
34 import org.onap.aaf.authz.layer.Result;
\r
35 import org.onap.aaf.dao.aaf.cass.DelegateDAO;
\r
36 import org.onap.aaf.dao.aaf.cass.DelegateDAO.Data;
\r
39 public class JU_DelegateDAO extends AbsJUCass {
\r
41 public void testCRUD() throws Exception {
\r
42 DelegateDAO dao = new DelegateDAO(trans, cluster, AUTHZ);
\r
43 DelegateDAO.Data data = new DelegateDAO.Data();
\r
44 data.user = "myname";
\r
45 data.delegate = "yourname";
\r
46 data.expires = new Date();
\r
49 ByteBuffer bb = data.bytify();
\r
50 Data bdata = new DelegateDAO.Data();
\r
51 bdata.reconstitute(bb);
\r
52 compare(data, bdata);
\r
56 Result<Data> ddcr = dao.create(trans,data);
\r
57 assertTrue(ddcr.isOK());
\r
61 Result<List<DelegateDAO.Data>> records = dao.read(trans,data.user);
\r
62 assertTrue(records.isOKhasData());
\r
63 for(DelegateDAO.Data rdata : records.value)
\r
64 compare(data,rdata);
\r
67 records = dao.readByDelegate(trans,data.delegate);
\r
68 assertTrue(records.isOKhasData());
\r
69 for(DelegateDAO.Data rdata : records.value)
\r
70 compare(data,rdata);
\r
73 data.delegate = "hisname";
\r
74 data.expires = new Date();
\r
75 assertTrue(dao.update(trans, data).isOK());
\r
78 records = dao.read(trans,data.user);
\r
79 assertTrue(records.isOKhasData());
\r
80 for(DelegateDAO.Data rdata : records.value)
\r
81 compare(data,rdata);
\r
84 records = dao.readByDelegate(trans,data.delegate);
\r
85 assertTrue(records.isOKhasData());
\r
86 for(DelegateDAO.Data rdata : records.value)
\r
87 compare(data,rdata);
\r
90 dao.delete(trans,data, true);
\r
91 records = dao.read(trans,data.user);
\r
92 assertTrue(records.isEmpty());
\r
100 private void compare(Data d1, Data d2) {
\r
101 assertEquals(d1.user, d2.user);
\r
102 assertEquals(d1.delegate, d2.delegate);
\r
103 assertEquals(d1.expires,d2.expires);
\r