/** * ============LICENSE_START==================================================== * org.onap.aaf * =========================================================================== * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved. * =========================================================================== * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * ============LICENSE_END==================================================== * */ package com.att.dao.aaf.test; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import java.nio.ByteBuffer; import java.util.Date; import java.util.List; import org.junit.Test; import org.onap.aaf.auth.dao.cass.DelegateDAO; import org.onap.aaf.auth.dao.cass.DelegateDAO.Data; import org.onap.aaf.auth.layer.Result; public class JU_DelegateDAO extends AbsJUCass { @Test public void testCRUD() throws Exception { DelegateDAO dao = new DelegateDAO(trans, cluster, AUTHZ); DelegateDAO.Data data = new DelegateDAO.Data(); // TODO: Clean out AT&T specific data data.user = "jg1555"; data.delegate = "rd8227"; data.expires = new Date(); // Bytification ByteBuffer bb = data.bytify(); Data bdata = new DelegateDAO.Data(); bdata.reconstitute(bb); compare(data, bdata); try { // Test create Result ddcr = dao.create(trans,data); assertTrue(ddcr.isOK()); // Read by User Result> records = dao.read(trans,data.user); assertTrue(records.isOKhasData()); for(DelegateDAO.Data rdata : records.value) compare(data,rdata); // Read by Delegate records = dao.readByDelegate(trans,data.delegate); assertTrue(records.isOKhasData()); for(DelegateDAO.Data rdata : records.value) compare(data,rdata); // Update // TODO: Clean out AT&T specific data data.delegate = "pf2819"; data.expires = new Date(); assertTrue(dao.update(trans, data).isOK()); // Read by User records = dao.read(trans,data.user); assertTrue(records.isOKhasData()); for(DelegateDAO.Data rdata : records.value) compare(data,rdata); // Read by Delegate records = dao.readByDelegate(trans,data.delegate); assertTrue(records.isOKhasData()); for(DelegateDAO.Data rdata : records.value) compare(data,rdata); // Test delete dao.delete(trans,data, true); records = dao.read(trans,data.user); assertTrue(records.isEmpty()); } finally { dao.close(trans); } } private void compare(Data d1, Data d2) { assertEquals(d1.user, d2.user); assertEquals(d1.delegate, d2.delegate); assertEquals(d1.expires,d2.expires); } }