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