9b0fa2ed28240b8a5a10d8b6fc45c3d5e74d168e
[aaf/authz.git] / authz-cass / src / test / java / org / onap / aaf / dao / aaf / test / JU_FastCalling.java
1 /*******************************************************************************\r
2  * ============LICENSE_START====================================================\r
3  * * org.onap.aaf\r
4  * * ===========================================================================\r
5  * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
6  * * ===========================================================================\r
7  * * Licensed under the Apache License, Version 2.0 (the "License");\r
8  * * you may not use this file except in compliance with the License.\r
9  * * You may obtain a copy of the License at\r
10  * * \r
11  *  *      http://www.apache.org/licenses/LICENSE-2.0\r
12  * * \r
13  *  * Unless required by applicable law or agreed to in writing, software\r
14  * * distributed under the License is distributed on an "AS IS" BASIS,\r
15  * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
16  * * See the License for the specific language governing permissions and\r
17  * * limitations under the License.\r
18  * * ============LICENSE_END====================================================\r
19  * *\r
20  * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
21  * *\r
22  ******************************************************************************/\r
23 package org.onap.aaf.dao.aaf.test;\r
24 \r
25 import static org.junit.Assert.assertEquals;\r
26 import static org.junit.Assert.assertTrue;\r
27 \r
28 import java.io.IOException;\r
29 import java.nio.ByteBuffer;\r
30 import java.security.NoSuchAlgorithmException;\r
31 import java.util.Date;\r
32 import java.util.List;\r
33 \r
34 import org.junit.Test;\r
35 import org.onap.aaf.authz.layer.Result;\r
36 import org.onap.aaf.dao.aaf.cass.CredDAO;\r
37 import org.onap.aaf.dao.aaf.cass.CredDAO.Data;\r
38 \r
39 import org.onap.aaf.inno.env.APIException;\r
40 \r
41 public class JU_FastCalling extends AbsJUCass {\r
42 \r
43         @Test\r
44         public void test() throws IOException, NoSuchAlgorithmException, APIException {\r
45                 trans.setProperty("cassandra.writeConsistency.cred","ONE");\r
46                 \r
47                 CredDAO udao = new CredDAO(env.newTransNoAvg(),cluster,"authz");\r
48                 System.out.println("Starting calls");\r
49                 for(iterations=0;iterations<8;++iterations) {\r
50                         try {\r
51                                 // Create\r
52                         CredDAO.Data data = new CredDAO.Data();\r
53                         data.id = "m55555@aaf.att.com";\r
54                         data.type = CredDAO.BASIC_AUTH;\r
55                         data.cred      = ByteBuffer.wrap(userPassToBytes("m55555","mypass"));\r
56                         data.expires = new Date(System.currentTimeMillis() + 60000*60*24*90);\r
57                                 udao.create(trans,data);\r
58                                 \r
59                                 // Validate Read with key fields in Data\r
60                                 Result<List<CredDAO.Data>> rlcd = udao.read(trans,data);\r
61                                 assertTrue(rlcd.isOKhasData());\r
62                                 for(CredDAO.Data d : rlcd.value) {\r
63                                         checkData1(data,d);\r
64                                 }\r
65                                 \r
66                                 // Update\r
67                                 data.cred = ByteBuffer.wrap(userPassToBytes("m55555","mynewpass"));\r
68                                 udao.update(trans,data);\r
69                                 rlcd = udao.read(trans,data);\r
70                                 assertTrue(rlcd.isOKhasData());\r
71                                 for(CredDAO.Data d : rlcd.value) {\r
72                                         checkData1(data,d);\r
73                                 }                       \r
74                                 \r
75                                 udao.delete(trans,data, true);\r
76                         } finally {\r
77                                 updateTotals();\r
78                                 newTrans();\r
79                         }\r
80                 }\r
81 \r
82         }\r
83 \r
84         private void checkData1(Data data, Data d) {\r
85                 assertEquals(data.id,d.id);\r
86                 assertEquals(data.type,d.type);\r
87                 assertEquals(data.cred,d.cred);\r
88                 assertEquals(data.expires,d.expires);\r
89         }\r
90 \r
91 }\r