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