Remove spaces from dockerbuild script
[aaf/authz.git] / auth / auth-cass / src / test / java / com / att / dao / aaf / test / JU_DelegateDAO.java
1 /**
2  * ============LICENSE_START====================================================
3  * org.onap.aaf
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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====================================================
19  *
20  */
21
22 package com.att.dao.aaf.test;
23
24
25 import static org.junit.Assert.assertEquals;
26 import static org.junit.Assert.assertTrue;
27
28 import java.nio.ByteBuffer;
29 import java.util.Date;
30 import java.util.List;
31
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;
36
37
38 public class JU_DelegateDAO  extends AbsJUCass {
39         @Test
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
44                 data.user = "jg1555";
45                 data.delegate = "rd8227";
46                 data.expires = new Date();
47                 
48 //        Bytification
49         ByteBuffer bb = data.bytify();
50         Data bdata = new DelegateDAO.Data();
51         bdata.reconstitute(bb);
52         compare(data, bdata);
53
54                 try {
55                         // Test create
56                         Result<Data> ddcr = dao.create(trans,data);
57                         assertTrue(ddcr.isOK());
58                         
59                         
60                         // Read by User
61                         Result<List<DelegateDAO.Data>> records = dao.read(trans,data.user);
62                         assertTrue(records.isOKhasData());
63                         for(DelegateDAO.Data rdata : records.value) 
64                                 compare(data,rdata);
65
66                         // Read by Delegate
67                         records = dao.readByDelegate(trans,data.delegate);
68                         assertTrue(records.isOKhasData());
69                         for(DelegateDAO.Data rdata : records.value) 
70                                 compare(data,rdata);
71                         
72                         // Update
73                         // TODO: Clean out AT&T specific data
74                         data.delegate = "pf2819";
75                         data.expires = new Date();
76                         assertTrue(dao.update(trans, data).isOK());
77
78                         // Read by User
79                         records = dao.read(trans,data.user);
80                         assertTrue(records.isOKhasData());
81                         for(DelegateDAO.Data rdata : records.value) 
82                                 compare(data,rdata);
83
84                         // Read by Delegate
85                         records = dao.readByDelegate(trans,data.delegate);
86                         assertTrue(records.isOKhasData());
87                         for(DelegateDAO.Data rdata : records.value) 
88                                 compare(data,rdata);
89
90                         // Test delete
91                         dao.delete(trans,data, true);
92                         records = dao.read(trans,data.user);
93                         assertTrue(records.isEmpty());
94                         
95                         
96                 } finally {
97                         dao.close(trans);
98                 }
99         }
100         
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);
105         }
106
107
108 }