2 * ============LICENSE_START====================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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====================================================
22 package com.att.dao.aaf.test;
24 import static junit.framework.Assert.assertEquals;
25 import static junit.framework.Assert.assertTrue;
27 import java.io.IOException;
28 import java.nio.ByteBuffer;
29 import java.util.List;
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;
42 * Utilize AbsJUCass to initialize and pre-load Cass
47 public class JU_LocateDAO extends AbsJUCass{
50 public void test() throws APIException, IOException {
51 LocateDAO pd = new LocateDAO(trans,cluster,CassAccess.KEYSPACE);
53 LocateDAO.Data data = new LocateDAO.Data();
54 data.name="org.osaaf.aaf.locateTester";
55 data.hostname="mithrilcsp.sbc.com";
57 data.latitude=32.780140f;
58 data.longitude=-96.800451f;
63 data.protocol="https";
64 Set<String> sp = data.subprotocol(true);
71 Result<Data> rpdc = pd.create(trans,data);
72 assertTrue(rpdc.isOK());
74 Result<List<LocateDAO.Data>> rlpd;
77 ByteBuffer bb = data.bytify();
78 Data bdata = new LocateDAO.Data();
79 bdata.reconstitute(bb);
82 // Validate Read with key fields in Data
83 rlpd = pd.read(trans,data);
84 assertTrue(rlpd.isOK());
86 for(LocateDAO.Data d : rlpd.value) {
91 // Validate Read by Name
92 rlpd = pd.readByName(trans,data.name);
93 assertTrue(rlpd.isOK());
95 for(LocateDAO.Data d : rlpd.value) {
101 data.latitude = -31.0000f;
103 Result<Void> rupd = pd.update(trans, data);
104 assertTrue(rupd.isOK());
105 rlpd = pd.read(trans,data);
106 assertTrue(rlpd.isOK());
108 for(LocateDAO.Data d : rlpd.value) {
113 } catch (IOException e) {
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);
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));