Remove spaces from dockerbuild script
[aaf/authz.git] / auth / auth-cass / src / test / java / com / att / dao / aaf / test / JU_LocateDAO.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 import static junit.framework.Assert.assertEquals;
25 import static junit.framework.Assert.assertTrue;
26
27 import java.io.IOException;
28 import java.nio.ByteBuffer;
29 import java.util.List;
30 import java.util.Set;
31
32 import org.junit.Test;
33 import org.onap.aaf.auth.dao.CassAccess;
34 import org.onap.aaf.auth.dao.cass.LocateDAO;
35 import org.onap.aaf.auth.dao.cass.LocateDAO.Data;
36 import org.onap.aaf.auth.layer.Result;
37 import org.onap.aaf.misc.env.APIException;
38
39 /**
40  * Test the LocateDAO
41  * 
42  * Utilize AbsJUCass to initialize and pre-load Cass
43  * 
44  * @author Jonathan
45  *
46  */
47 public class JU_LocateDAO extends AbsJUCass{
48
49         @Test
50         public void test() throws APIException, IOException {
51                 LocateDAO pd = new LocateDAO(trans,cluster,CassAccess.KEYSPACE);
52                 try {
53                         LocateDAO.Data data = new LocateDAO.Data();
54                         data.name="org.osaaf.aaf.locateTester";
55                         data.hostname="mithrilcsp.sbc.com";
56                         data.port=19999;
57                         data.latitude=32.780140f;
58                         data.longitude=-96.800451f;
59                         data.major=2;
60                         data.minor=0;
61                         data.patch=19;
62                         data.pkg=23;
63                         data.protocol="https";
64                         Set<String> sp = data.subprotocol(true);
65                         sp.add("TLS1.1");
66                         sp.add("TLS1.2");
67                         
68
69
70                         // CREATE
71                         Result<Data> rpdc = pd.create(trans,data);
72                         assertTrue(rpdc.isOK());
73
74                         Result<List<LocateDAO.Data>> rlpd;
75                         try {
76 //                      Bytification
77                         ByteBuffer bb = data.bytify();
78                         Data bdata = new LocateDAO.Data();
79                         bdata.reconstitute(bb);
80                         compare(data, bdata);
81
82                                 // Validate Read with key fields in Data
83                         rlpd = pd.read(trans,data);
84                         assertTrue(rlpd.isOK());
85                         if(rlpd.isOK()) {
86                                         for(LocateDAO.Data d : rlpd.value) {
87                                                 compare(data,d);
88                                         }
89                         }
90
91                         // Validate Read by Name
92                         rlpd = pd.readByName(trans,data.name);
93                         assertTrue(rlpd.isOK());
94                         if(rlpd.isOK()) {
95                                         for(LocateDAO.Data d : rlpd.value) {
96                                                 compare(data,d);
97                                         }
98                         }
99
100                                 // Modify
101                                 data.latitude = -31.0000f;
102                                 
103                                 Result<Void> rupd = pd.update(trans, data);
104                                 assertTrue(rupd.isOK());
105                         rlpd = pd.read(trans,data);
106                         assertTrue(rlpd.isOK());
107                         if(rlpd.isOK()) {
108                                         for(LocateDAO.Data d : rlpd.value) {
109                                                 compare(data,d);
110                                         }
111                         }
112
113                         } catch (IOException e) {
114                                 e.printStackTrace();
115                         } finally {
116                                 // DELETE
117                                 Result<Void> rpdd = pd.delete(trans,data,true);
118                                 assertTrue(rpdd.isOK());
119                                 rlpd = pd.read(trans, data);
120                                 assertTrue(rlpd.isOK() && rlpd.isEmpty());
121                                 assertEquals(rlpd.value.size(),0);
122                         }
123                 } finally {
124                         pd.close(trans);
125                 }
126         }
127
128         private void compare(Data a, Data b) {
129                 assertEquals(a.name,b.name);
130                 assertEquals(a.hostname,b.hostname);
131                 assertEquals(a.port,b.port);
132                 assertEquals(a.major,b.major);
133                 assertEquals(a.minor,b.minor);
134                 assertEquals(a.patch,b.patch);
135                 assertEquals(a.pkg,b.pkg);
136                 assertEquals(a.latitude,b.latitude);
137                 assertEquals(a.longitude,b.longitude);
138                 assertEquals(a.protocol,b.protocol);
139                 Set<String> spa = a.subprotocol(false);
140                 Set<String> spb = b.subprotocol(false);
141                 assertEquals(spa.size(),spb.size());
142                 for(String s : spa) {
143                         assertTrue(spb.contains(s));
144                 }
145         }
146 }