Remove spaces from dockerbuild script
[aaf/authz.git] / auth / auth-cass / src / test / java / org / onap / aaf / auth / dao / aaf / test / JU_DelegateDAO.java
1 /*******************************************************************************
2  * ============LICENSE_START====================================================
3  * * org.onap.aaf
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
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 org.onap.aaf.auth.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                 data.user = "myname";
44                 data.delegate = "yourname";
45                 data.expires = new Date();
46                 
47 //        Bytification
48         ByteBuffer bb = data.bytify();
49         Data bdata = new DelegateDAO.Data();
50         bdata.reconstitute(bb);
51         compare(data, bdata);
52
53                 try {
54                         // Test create
55                         Result<Data> ddcr = dao.create(trans,data);
56                         assertTrue(ddcr.isOK());
57                         
58                         
59                         // Read by User
60                         Result<List<DelegateDAO.Data>> records = dao.read(trans,data.user);
61                         assertTrue(records.isOKhasData());
62                         for(DelegateDAO.Data rdata : records.value) 
63                                 compare(data,rdata);
64
65                         // Read by Delegate
66                         records = dao.readByDelegate(trans,data.delegate);
67                         assertTrue(records.isOKhasData());
68                         for(DelegateDAO.Data rdata : records.value) 
69                                 compare(data,rdata);
70                         
71                         // Update
72                         data.delegate = "hisname";
73                         data.expires = new Date();
74                         assertTrue(dao.update(trans, data).isOK());
75
76                         // Read by User
77                         records = dao.read(trans,data.user);
78                         assertTrue(records.isOKhasData());
79                         for(DelegateDAO.Data rdata : records.value) 
80                                 compare(data,rdata);
81
82                         // Read by Delegate
83                         records = dao.readByDelegate(trans,data.delegate);
84                         assertTrue(records.isOKhasData());
85                         for(DelegateDAO.Data rdata : records.value) 
86                                 compare(data,rdata);
87
88                         // Test delete
89                         dao.delete(trans,data, true);
90                         records = dao.read(trans,data.user);
91                         assertTrue(records.isEmpty());
92                         
93                         
94                 } finally {
95                         dao.close(trans);
96                 }
97         }
98         
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);
103         }
104
105
106 }