1 /*******************************************************************************
\r
2 * ============LICENSE_START====================================================
\r
4 * * ===========================================================================
\r
5 * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
\r
6 * * Copyright © 2017 Amdocs
\r
7 * * ===========================================================================
\r
8 * * Licensed under the Apache License, Version 2.0 (the "License");
\r
9 * * you may not use this file except in compliance with the License.
\r
10 * * You may obtain a copy of the License at
\r
12 * * http://www.apache.org/licenses/LICENSE-2.0
\r
14 * * Unless required by applicable law or agreed to in writing, software
\r
15 * * distributed under the License is distributed on an "AS IS" BASIS,
\r
16 * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
17 * * See the License for the specific language governing permissions and
\r
18 * * limitations under the License.
\r
19 * * ============LICENSE_END====================================================
\r
21 * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
\r
23 ******************************************************************************/
\r
24 package com.att.dao.aaf.test;
\r
27 import static org.junit.Assert.assertEquals;
\r
28 import static org.junit.Assert.assertTrue;
\r
30 import java.nio.ByteBuffer;
\r
31 import java.util.Date;
\r
32 import java.util.List;
\r
34 import org.junit.Test;
\r
36 import com.att.authz.layer.Result;
\r
37 import com.att.dao.aaf.cass.DelegateDAO;
\r
38 import com.att.dao.aaf.cass.DelegateDAO.Data;
\r
41 public class JU_DelegateDAO extends AbsJUCass {
\r
43 public void testCRUD() throws Exception {
\r
44 DelegateDAO dao = new DelegateDAO(trans, cluster, AUTHZ);
\r
45 DelegateDAO.Data data = new DelegateDAO.Data();
\r
46 data.user = "myname";
\r
47 data.delegate = "yourname";
\r
48 data.expires = new Date();
\r
51 ByteBuffer bb = data.bytify();
\r
52 Data bdata = new DelegateDAO.Data();
\r
53 bdata.reconstitute(bb);
\r
54 compare(data, bdata);
\r
58 Result<Data> ddcr = dao.create(trans,data);
\r
59 assertTrue(ddcr.isOK());
\r
63 Result<List<DelegateDAO.Data>> records = dao.read(trans,data.user);
\r
64 assertTrue(records.isOKhasData());
\r
65 for(DelegateDAO.Data rdata : records.value)
\r
66 compare(data,rdata);
\r
69 records = dao.readByDelegate(trans,data.delegate);
\r
70 assertTrue(records.isOKhasData());
\r
71 for(DelegateDAO.Data rdata : records.value)
\r
72 compare(data,rdata);
\r
75 data.delegate = "hisname";
\r
76 data.expires = new Date();
\r
77 assertTrue(dao.update(trans, data).isOK());
\r
80 records = dao.read(trans,data.user);
\r
81 assertTrue(records.isOKhasData());
\r
82 for(DelegateDAO.Data rdata : records.value)
\r
83 compare(data,rdata);
\r
86 records = dao.readByDelegate(trans,data.delegate);
\r
87 assertTrue(records.isOKhasData());
\r
88 for(DelegateDAO.Data rdata : records.value)
\r
89 compare(data,rdata);
\r
92 dao.delete(trans,data, true);
\r
93 records = dao.read(trans,data.user);
\r
94 assertTrue(records.isEmpty());
\r
102 private void compare(Data d1, Data d2) {
\r
103 assertEquals(d1.user, d2.user);
\r
104 assertEquals(d1.delegate, d2.delegate);
\r
105 assertEquals(d1.expires,d2.expires);
\r