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 com.att.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
35 import com.att.authz.layer.Result;
\r
36 import com.att.dao.aaf.cass.DelegateDAO;
\r
37 import com.att.dao.aaf.cass.DelegateDAO.Data;
\r
40 public class JU_DelegateDAO extends AbsJUCass {
\r
42 public void testCRUD() throws Exception {
\r
43 DelegateDAO dao = new DelegateDAO(trans, cluster, AUTHZ);
\r
44 DelegateDAO.Data data = new DelegateDAO.Data();
\r
45 data.user = "myname";
\r
46 data.delegate = "yourname";
\r
47 data.expires = new Date();
\r
50 ByteBuffer bb = data.bytify();
\r
51 Data bdata = new DelegateDAO.Data();
\r
52 bdata.reconstitute(bb);
\r
53 compare(data, bdata);
\r
57 Result<Data> ddcr = dao.create(trans,data);
\r
58 assertTrue(ddcr.isOK());
\r
62 Result<List<DelegateDAO.Data>> records = dao.read(trans,data.user);
\r
63 assertTrue(records.isOKhasData());
\r
64 for(DelegateDAO.Data rdata : records.value)
\r
65 compare(data,rdata);
\r
68 records = dao.readByDelegate(trans,data.delegate);
\r
69 assertTrue(records.isOKhasData());
\r
70 for(DelegateDAO.Data rdata : records.value)
\r
71 compare(data,rdata);
\r
74 data.delegate = "hisname";
\r
75 data.expires = new Date();
\r
76 assertTrue(dao.update(trans, data).isOK());
\r
79 records = dao.read(trans,data.user);
\r
80 assertTrue(records.isOKhasData());
\r
81 for(DelegateDAO.Data rdata : records.value)
\r
82 compare(data,rdata);
\r
85 records = dao.readByDelegate(trans,data.delegate);
\r
86 assertTrue(records.isOKhasData());
\r
87 for(DelegateDAO.Data rdata : records.value)
\r
88 compare(data,rdata);
\r
91 dao.delete(trans,data, true);
\r
92 records = dao.read(trans,data.user);
\r
93 assertTrue(records.isEmpty());
\r
101 private void compare(Data d1, Data d2) {
\r
102 assertEquals(d1.user, d2.user);
\r
103 assertEquals(d1.delegate, d2.delegate);
\r
104 assertEquals(d1.expires,d2.expires);
\r